[SQL] how two related tables query?

For example: I have two tables table1 and table2 table1: id name sex 1 Joe Smith John Doe 2 men and 3 women and five men table2 Wang: ... For example: I have two tables table1 and table2
table1:
the above mentioned id name Sex 

1 Male Joe Smith
2 John Doe female
3 king five men

table2:
the above mentioned id Hobby Lid

1 chess 2
2 game 3
3 Music 2
4 1 learning

at the same time find out table2 table table1 Lid when I want to check out the data table id = 2 = 2 data
I used to use the feeling is twice query method efficiency is much lower.
select * from table1 where id = 1 ;
first find the table of contents in table1

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

this is not efficient query twice. I do not know what method is directly related to the query? Collapse
The main query id wrong this mean?
Best answer
 
select * from table1 a,table2 b
where a.id = b.lid
 
Asked
Ah, thank you indeed the case, but should 
select * from table1 a, table2 b where a.id = 1 and a.id = b.lid it's only perfect

Guess you like

Origin www.cnblogs.com/ZHENGJUNupperclassman/p/10977749.html