table1
id name level
1 张三 101
table2
id name category
101 高手 A
201 高高手 B 通过table1中id查出如下显示
table1.id table1.name table1.level table2.name table2.category
1 张三 101 高手 A请看清楚我的需求:根据 table1 中 id 查的如上结果 另外 table1 中字段非常多 请用* 代替
id name level
1 张三 101
table2
id name category
101 高手 A
201 高高手 B 通过table1中id查出如下显示
table1.id table1.name table1.level table2.name table2.category
1 张三 101 高手 A请看清楚我的需求:根据 table1 中 id 查的如上结果 另外 table1 中字段非常多 请用* 代替
select *
from table1 a join table2 b on a.id = b.id
from table1 left join table2 on table1.level = table2.id
select *
from table1 a join table2 b on a.[level] = b.id
1楼写错了。
set @id=5 --这儿输入你要查的ID
select table1.*,table2.name,table2.category
from table1 inner join table2 on table1.level=table2.id
where table1.id=@id
from table1 a left join table 2 b on a.level=b.id
你们都忽略 一个问题 结果集是根据 table1.id 查询出来的
select *
from table1 a join table2 b on a.level = b.id and a.id = ?