select task.id, task.name, proj.id, proj.name
from tasks task left join projects proj on proj.id=task.project_id;
Using left join ensures you get something even if there is no record in the projects table. If you want to ensure coherency, you may do
select task.id, task.name, proj.id, proj.name
from tasks task, projects proj
where proj.id=task.project_id;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…