两表之间相同字段查询
A表
表id 用户ID 图片 栏目
1 5 1.jpg 10
2 6 4.jpg 18
B表
表id 用户ID 用户名
1 5 张三
2 6 李四
如何查询查询出图片的同时,对比用户ID字段,把用户名也查询出来
我原来是这么写的 试了几种都不对.实在没办法了,上来像CSDN的大大们求教下..
select top 7 * from A "+ "inner join B on A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
select top 7 * from A B where A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
select top 7 * from A a, B b, where a.用户ID=b.用户ID and a.栏目=18 order by a.表ID desc
select top 7 * from A inner join B on A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
------解决方案--------------------最后一句理论上应该可行,换成外连接试试。
select top 7 * from A left join B on A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
------解决方案--------------------Select b.用户名,a.* from A表 as a
inner Join B表 as b on a.用户ID=b.用户ID and a.栏目=18
------解决方案----------------------1
select top 7 * from A
inner join B on A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
--2
select top 7 * from A, B
where A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc
--3
select top 7 * from A a, B b,
where a.用户ID=b.用户ID and a.栏目=18 order by a.表ID desc
--4
select top 7 * from A
inner join B on A.用户ID=B.用户ID and A.栏目=18 order by A.表ID desc