簡體   English   中英

SQL查詢 - 從另一個表中獲取名稱

[英]SQL Query - Get Name from another table

基本上我有2個表: uclk_useruclk_task

uclk_user表有user_idnamepostcode

uclk_task表有user_idjob_iddescriptionfully_completeddate_due

我想在下面的任務查詢中包含uclk_user中的用戶名...顯然user_id是關鍵。

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

應該怎么做?

使用JOIN從通用條件中的多個表中進行選擇

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

試試這個

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM