菜鸟问题,大家帮我看看这条语句怎么出现笛卡尔乘积了那?
select book.name,music.name from book,music
where book.id in(1011,2011) or music.id in(1011,2011)
数据库中我的book表的id为 "10 "开头的,music表的id为“20”开头的
[解决办法]
select book.name,music.name from book,music
等价于:
select book.name,music.name from book CROSS JOIN music
交叉联接将产生联接所涉及的表的笛卡尔积.
不知道楼主给的表结构及表间的关联、和想要的结果是什么,无法定论。
select book.name,music.name from book,music
where book.id in(1011,2011) or music.id in(1011,2011)
只能说,语法没错。
根据‘这两张表没有关联的’,楼主可以考虑这样,看是否满足要求:
SELECT [name] FROM book WHERE [id] IN(1011,2011)
UNION ALL SELECT [name] FROM music WHERE [id] IN(1011,2011)