需要通过连接两个表(左外连接)来显示记录。记录应该是唯一的 [英] Need to display records by joining two tables ( left outer join) .the records should be unique

查看:82
本文介绍了需要通过连接两个表(左外连接)来显示记录。记录应该是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表student和TaskEffort。许多学生必须完成同样的任务。对于特殊任务,应考虑学生姓名和努力。

学生表包含学生信息,TaskEffort表包含taskid,studentid,Effort



我需要显示taskid,名字,姓氏,努力。对于那些从事特定任务的人。



我试过的查询是

I have two tables student and TaskEffort. Many students must have worked on same task. For particular task the name of the students and effort should be considered.
The student table contains students info and TaskEffort table contains taskid, studentid, Effort

I need to display the taskid,first name,last name,effort. For those who worked on particular task.

Query I tried is

SELECT t.id, s.firstname,s.lastname, t.effort 
FROM taskeffort t 
LEFT OUTER JOIN student s ON t.id = 4 AND s.studentid = t.studentid



我只需要输出任务我4但我得到的所有任务ID。



有人可以帮我解决


I need output only for task I'd 4 but I am getting for all task id .

Can someone help me out

推荐答案

您好,



您的加入会导致问题。



Hello,

Your join is causing issues.

SELECT t.id, s.firstname,s.lastname, t.effort
FROM taskeffort t
LEFT OUTER JOIN student s ON s.studentid = t.studentid
WHERE t.id = 4





如果你只想得到任务id = 4的记录,那么应该在WHERE子句中添加它。



RelicV



If you want to get only task id = 4 records, it should be added in WHERE clause.

RelicV


这篇关于需要通过连接两个表(左外连接)来显示记录。记录应该是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆