【SQL】如何两张表关联查询?

比如:我有table1 和 table2 两张表table1: id name sex 1 张三 男 2 李四 女 3 王五 男table2: ...比如:我有table1 和 table2 两张表
table1:
id name sex 

1 张三 男
2 李四 女
3 王五 男

table2:
id hobby Lid

1 下棋 2
2 游戏 3
3 音乐 2
4 学习 1

我现在想当table1表里查询出id=2的数据时同时查出table2表里 Lid=2的数据
我以前使用的是两次查询方法感觉效率要低很多。
select * from table1 where id=1;
先查出table1表内容 在

select * from table2 where Lid in(select * from table1 where id=1);

这样是查询了两遍效率不高。不知道直接关联查询的方法是什么?收起
查询id写错的主要这个意思?
最佳答案
 
select * from table1 a,table2 b
where a.id = b.lid
 
追问
嗯,谢谢了的确是这样的不过应该
select * from table1 a,table2 b where a.id=1 and a.id=b.lid 这样才算完美了
原文地址:https://www.cnblogs.com/ZHENGJUNupperclassman/p/10977749.html