SQL 查询两张数据不同的表

表A中有两条数据 表B中有五条数据 可以用sql查询出所有的数据么,表B有表A的外键字段

select * from A a niuonAll select * from B b

select * from A a ,B b where a.aa=b.bb//关联查询

可以的 select * from A,B where B.主键 = A.外键

"select * from b left jion a where b.fk = a.id"

根据你要查询表的内容可以分为以下几种情况 http://blog.csdn.net/qq_36336328/article/details/73772205

select * from 表一 inner join 表二 on 表一的主鍵或外鍵 =表二的主鍵或外鍵

一、外连接

外连接可分为:左连接、右连接、完全外连接。

1、左连接 left join 或 left outer join

SQL语句:select * from student left join course on student.ID=course.ID

用外链接,依赖A表就可以了

"select * from a left jion b where b.fk = a.id"

union or unionall

select * from a
left join b where a.sameA=b.sameB