如何组合来自2个表的sql语句

时间:2018-03-13 22:01:15

标签: sql

我有两个可用的sql语句:

select firstName from table1 s INNER JOIN  table2 t ON s.LoginId = t.userId

select testScore from table2 where userId in (select loginId from table1)

如何组合这些陈述

firstName
第一个语句的

被添加到第二个语句的输出中(即输出产生firstName和testScore?

1 个答案:

答案 0 :(得分:1)

您只需要JOIN两个表格。你已经这样做了,所以也许你的问题中缺少一些信息或要求,为什么以下不起作用?

SELECT s.firstName, t.testScore
FROM table1 s
INNER JOIN table2 t ON (s.LoginId = t.userId)