4

Basically I have 2 tables: uclk_user and uclk_task

uclk_user table has user_id, name, postcode

uclk_task table has user_id, job_id, description, fully_completed, date_due

I want to include the user name from the uclk_user in my task query below... Obviously user_id is the key.

select job_id, user_id, fully_completed, description, date_due
from uclk_task
WHERE date_due <= NOW() AND fully_completed = 0
ORDER BY date_due ASC

How this should be done?

4

2 回答 2

6

Use JOIN to select from multiple tables on a common criteria

SELECT t.job_id, t.user_id, t.fully_completed, t.description, t.date_due, u.name
FROM uclk_task t
INNER JOIN uckl_user u
ON t.user_id = u.user_id
WHERE t.date_due <= NOW() AND t.fully_completed = 0
ORDER BY t.date_due ASC
于 2012-08-26T11:34:45.670 回答
1

try this

 select job_id, user_id, fully_completed, description, date_due
    from uclk_task
    Left join
    on date_due <= NOW() AND fully_completed = 0
    ORDER BY date_due ASC
于 2012-08-26T11:39:33.887 回答