我被困在2个数据库的结果集中,通过提供查询来帮助我
table 1:
id name email
1 name1 nam1@gmail.com
2 name2 nam2@gmail.com
3 name3 nam3@gmail.com
table 2:
id
2
现在,我有第一个表的查询
select * from table1 where email='nam3@gmail.com'
并查询第二个表
select * from table2
现在,我需要
的结果id name email
3 name3 nam3@gmail.com(first query result)
2 name2 nam2@gmail.com(second query result)
答案 0 :(得分:1)
如果我理解正确,你需要:
SELECT t1.*
FROM table1 AS t1
LEFT JOIN table2 AS t2
ON t1.id = t2.id
WHERE A.email='nam3@gmail.com'
OR t2.id = 2
答案 1 :(得分:0)
select * from table1 where email='nam3@gmail.com
union all
select * from table1 where id in (select id from Table2)