简单的sql 语句 2张表里查
(1)忽略掉:无出版商的书、无书的出版商
select publishers.pub_name,t1.title from publishers
inner join
(select title_id,title,pub_id from titles) t1
on publishers.pub_id=t1.pub_id
(2)包括无书的出版商,忽略无出版商的书:
select publishers.pub_name,t1.title from publishers
left join
(select title_id,title,pub_id from titles) t1
on publishers.pub_id=t1.pub_id
(3)包括无出版商的书,忽略无书的出版商:
select publishers.pub_name,t1.title from publishers
right join
(select title_id,title,pub_id from titles) t1
on publishers.pub_id=t1.pub_id
以出版商publishers 表为基表 ,右关联书籍 titles表,显示你需要的结果:全部出版商和对应数据的数据。
语句如下:
select a.pub_name,b.title
from publishers a
left join titles b on a.pub_id=b.pub_id b
select a.pub_name,b.title from publishers a,titles b where a.pub_id=b.pub_id and b.title is not null;
有问题再追问,望采纳。
求一句简单的SQL两表关联查询语句~
select a.*
from a, b
where a.a1 b.b1 or a.a2b.b2 or a.a3b.b3
或
select a.*
from a, b
where not (a.a1=b.b1 and a.a2=b.b2 and a.a3=b.b3)
或
select a.*
from a
where not exists(select * from b where b.b1=a.a1 and b.b2=a.a2 and b.b3=a.a3)
如果最高分不只一个呢.....
select * from Result where grade=1 and gender='男' and score = (select max(score) from result);
select * from Result where grade=1 and score=(select max(score) from Result);
select * from Result where gender='女'and score=(select max(score) from Result);
select * from Result where score in (select max(score) from Result group by grade);
注:
grade 年级
name 姓名
gender 性别
score 分数
谁用谁知道!