SQL查询两张表

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:33:08
表A
id name xuhao
自动.字符.数字
表B
id 内容 xuhao
自动.字符.数字
表A xuhao字段和表B xuhao字段关联
问题:根据表A的序号字段查询出表B里所有相关记录

select b.*
from A a,B b
where a.xuhao = b.xuhao

如果你没有在数据库当中做关联,就这样做
select * from 表A a,表B b where a.id="要查找的数据" and a.xuhao=b.xuhao
如果你关联了。就直接

select * from 表A a,表B b where a.id="要查找的数据"

select *
from B inner join A
on A.xuhao=B.xuhao
where A.id='查找内容'

select b.id, b.内容,b.xuehao from 表A a,表B b where a.id="要查找的数据" and a.xuhao=b.xuhao

select *
from A,B
where A.xuhao=B.xuhao