Reputation: 117
table1 - user
uid (int)
user_name (varchar)
job (int) relation to table2 `job`.`job_id`
table2 job
job_id (int)
job_name (varchar)
I want my user search the job_name or user_name can show in the one result
+-------------------------------------------------------------+
| uid | user_name | job | object1 | object2 | sortID |
+------------------------------------------------------------+
| 12345 | Joe | 1 | 222 | 444 | 66 |
| 12346 | John | 2 | 222 | 444 | 66 |
| 12347 | David | 30 | 333 | 444 | 66 |
| 12355 | Peter | 50 | 333 | 555 | 77 |
+------------------------------------------------------------+
+-------------------------+
| job_id | job_name |
+------------------------+
| 1 | teacher |
| 2 | doctor |
| 3 | driver |
| 50 | it support |
+------------------------+
I want to search doctor I can see John information
How to create my sql statement?
Upvotes: 1
Views: 32
Reputation: 106
Select u.user_name, j.job_name from user u left join job j on j.job_id = u.job_name where j.job like "%$key%";
That was what i understanded of your question :)
Upvotes: 1