表A:
ID number(11) null,
content_type number(4) not null,
content varchar(255) null表B:
id type
1 XX
1 XX
2 YY
2 YY
问题:
想打印出表A,必须去关联表B,content_type 去关联表B的id字段,但是表B的id字段可能有两条相同的信息 如何查询才行呢
select a.id ,B.type,content from A left join B on A.content_type=B.id
好像出来的记录有肯能重复
ID number(11) null,
content_type number(4) not null,
content varchar(255) null表B:
id type
1 XX
1 XX
2 YY
2 YY
问题:
想打印出表A,必须去关联表B,content_type 去关联表B的id字段,但是表B的id字段可能有两条相同的信息 如何查询才行呢
select a.id ,B.type,content from A left join B on A.content_type=B.id
好像出来的记录有肯能重复
where cntent_type in (select id from B);
select distinct a.id ,B.type,content
from A left join B on A.content_type=B.id