从两个表中选择一条记录

I'm stuck with one SQL query. I have two tables:

  1. users

    ________________________
    | id | company | worker|
    -------------------------
    | 1  | my comp | John  |
    
  2. tasks

    _________________________
    | id | name | company   |
    -------------------------
    | 1  | exm  | my comp   |
    

My problem is that I want to show tasks of these companies which worker is John. I'm in trouble in that for hours but I don't know how to do it. Is there any SQL query to do that?

You can do a simple join using company column from both tables and use where clause to filter results for John

SELECT t.*
FROM users u
JOIN tasks t USING(company)
WHERE u.worker ='John'

You want use the inner join tag. Just a modification on the other queries mentioned for better clarity.

SELECT task.name,user.worker,user.company 
FROM tasks as task INNER JOIN users as user 
 ON user.company=task.company 
 WHERE user.worker='John';

You can do a simple join like...

$qry = "SELECT u.id,u.company,u.worker,t.id,t.name,t.company FROM users as u JOIN tasks as t ON u.company = t.company WHERE u.worker = 'John'";