读书人

帮忙看下sql如何写

发布时间: 2012-02-29 16:44:11 作者: rapoo

求救,大虾帮忙看下sql怎么写
各位大虾,小弟数据库方面不太熟悉,现在业务上碰到了个比较棘手的问题,需要写个sql查询,如下:
假设我现在有三张表: A表 B表 C表

A表:
id 厂商名称 产品名 ....
1 康师傅 红茶 ....
2 统一 红茶 ....
3 汇源 红茶 ....

B表:
id 厂商名称 产品名 ....
1 统一 大骨面 ....
2 统一 米粉 ....
3 康师傅 大骨面....

C表:
id 厂商名称 产品名 ....
1 康师傅 鲜橙多 ....
2 康师傅 鲜橙多 ....

.............. 写这么点都快累死我了,费脑筋...呵呵

然后现在我想要的是查询出来这样的结果 :

康师傅
统一
汇源



大家可能都明白了,我就是想要三张表中所有的厂商的名称,而且不需要重复的,希望大家支支招...拜谢喽~!


[解决办法]
select 厂商名称 from A
union
select 厂商名称 from B
union
select 厂商名称 from C
;
[解决办法]
seelct distinct 厂商名称 from (
select 厂商名称 from A
union
select 厂商名称 from B
union
select 厂商名称 from C);
[解决办法]

SQL code
select 厂商名称 from A where parentID = 111unionselect 厂商名称 from B where parentID = 111unionselect 厂商名称 from C where parentID = 111
[解决办法]
探讨
谢谢大家了,出来了 呵呵 ...........泪流满面.....
语句就是根据大家的帮忙写的:
select DISTINCT provider_name FROM(select brd.provider_name from BTS_REQ_DETAIL brd
where brd.cp_req_order_id = 10298
union
select bsc.provider_na……

读书人网 >oracle

热点推荐