简体   繁体   English

如何在MySQL中搜索并获取结果?

[英]How do I search this in MySQL and get result?

table1 表格1

name   | designation
------------------
john   | engineer
mathew | IT consultant
Neil   | SAP
Tom    | webdeveloper
david  | egineer
kane   | engineer

I do have above same names in a text file too. 我的文本文件中确实也有相同的名字。 when I search names from text file then I need to grab designation of that name then search with that designation and list names with that designation. 当我从文本文件中搜索名称时,我需要获取该名称的名称,然后使用该名称进行搜索,并使用该名称列出名称。

for example if I search by John then I want get result as john = david,kane 例如,如果我按John进行搜索,那么我想得到john = david,kane

how can I do this with PHP and MySQL?? 我该如何使用PHP和MySQL?

SELECT
  t2.name
FROM
  table1 t1
INNER JOIN
  table1 t2
ON
  t1.designation = t2.designation
WHERE
  t1.name = 'John'
AND
  t2.name != 'John'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM