日期:2014-05-17 浏览次数:20993 次
SELECT 表A.numA, sun, moon, null star, conntent
FROM 表B,表A
WHERE 表B.numA = 表A.numA
UNION ALL
SELECT 表A.numA, sun,null moon, star, conntent
FROM 表C,表A
WHERE 表C.numA = 表A.numA
ORDER BY numA
/*建表*/
create table tableA
(
numA varchar(10),
content varchar(10)
)
create table tableB
(
numA varchar(10),
sun varchar(10),
moon varchar(10)
)
create table tableC
(
numA varchar(10),
sun varchar(10),
star varchar(10)
)
/*插值*/
insert into tableA values ('黄','好人')
insert into tableA values ('刘','坏人')
insert into tableA values ('张','傻瓜')
insert into tableB values ('黄','很大','很小')
insert into tableB values ('黄','中间','一般大')
insert into tableB values ('刘','还好','微小')
insert into tableC values ('黄','很大','很小')
insert into tableC values ('张','中间','一般大')
/*查询*/
select a.numA,b.sun,b.moon,c.star,a.content
from tableA a
left join tableB b on a.numA=b.numA
left join tableC c on a.numA=c.numA
CREATE TABLE A
(
numA varchar(10),
conntent varchar(30)
)
INSERT INTO A
SELECT '黄','好人' UNION ALL
SELECT '刘','坏人' UNION ALL
SELECT '张','傻瓜'
CREATE TABLE B
(
numA varchar(10),
sun varchar(10),
moon varchar(30)
)
INSERT INTO B
SELECT '黄','很大','很小' UNION ALL
SELECT '黄','中间','一般大' UNION ALL
SELECT '刘','还好','微小'
CREATE TABLE C
(
numA varchar(10),
sun varchar(10),
star varchar(30)
)
INSERT INTO C
SELECT '黄','很大','很小' UNION ALL
SELECT '张','中间','一般大'
select A.numA, C.sun, B.moon,C.star,A.conntent from A full join B on A.numA=B.numA
left join C on A.numA=C.numA
/*
numA sun moon star conntent