This question already has an answer here:
I have 3 tables
Table 1- Users:
_______________________
|uid | uname |
|______|______________|
| 1 | John99 |
| 2 | Steve12 |
| 3 | Smith_a |
| 4 | Robert.t |
| 5 | Williams.a |
|______|______________|
Table 2-Firstname:
_____________________
|eid | fname |
|______|_____________|
|1 | John |
|2 | Steve |
|3 | Williams |
|4 | Thomas |
|5 | James |
|______|_____________|
Table 3- Lastname
____________________
|eid | lname |
|______|____________|
|1 | Williams |
|2 | George |
|3 | Smith |
|4 | Robert |
|5 | Heart |
|___________________|
user can search with keyword 'will' or 'williams'. i need to search this key word from all the above 3 tables and display uid, fname and lname for that respective keyword. example: 1.John Williams 3.Williams Smith 5.James Heart
i tried union along with like '%will%'but there are duplicates returned in result. can someone help me with the query.
Thanks.
Assuming
eid
is a foreign key touid
, then something like this should work:If you also need to search the uname field, then add that to your where criteria with another or statement.
Results: