1

I have two tables. The structure is :

mysql> desc working;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| worker_id   | varchar(12) | YES  |     | NULL    |       | 
| worker_duty | varchar(30) | YES  |     | NULL    |       | 
| salary      | varchar(8)  | YES  |     | NULL    |       | 
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> desc users;
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| user_id     | varchar(12)  | YES  |     | NULL    |       | 
| user_name   | varchar(21)  | YES  |     | NULL    |       | 
| discription | varchar(200) | YES  |     | NULL    |       | 
+-------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

I want to join this two table using worker_id and user_id and fetch it using PHP.

I use :

SELECT * from users t1
WHERE user_id="293274"
AND SELECT worker_duty ,worker_id from working t2
             WHERE t1.user_id= t2.worker_id

But this code does not work.

4 Answers 4

2

inner join

select u.user_id, u.user_name, u.discription, w.worker_duty
from users u
inner join working w on w.worker_id = u.user_id
where u.user_id = "293274";
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe like this ?

 'SELECT u.user_id, u.user_name, u.discription, w.worker_duty FROM users as u
 JOIN working as w ON u.user_id=w.worker_id
 WHERE w.user_id="293274"

Comments

0

Use join as below:

     SELECT t1.*,  t2.worker_duty , t2.worker_id  
     from users t1 JOIN working t2
          ON t1.user_id= t2.worker_id 
     WHERE t1.user_id="293274"

Comments

0

SELECT users.user_id, users.user_name, user.discription, working.working_duty FROM user JOIN working ON user.user_id = working.worker_id WHERE user.user_id="293274"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.