[英]Column 'book-category' in where clause is ambiguous
I'm facing a problem in this sql query 我在这个SQL查询中遇到了问题
SELECT * FROM `book` join `journal`
WHERE `book-category` LIKE '$maincat2'
AND `book-category` LIKE '$subcat2'
AND `book-category` LIKE '$country2'
AND `book-category` LIKE '$procat2'
the table strukture are same book=journal 桌子是同一本书=期刊
What is the reason? 是什么原因?
both book
and journal
have a book-category
column, so MySQL doesn't know which one to apply the condition on. book
和journal
都有一个book-category
列,所以MySQL不知道哪一个应用了这个条件。 You can solve this by fully referencing them with a table name. 您可以通过使用表名完全引用它们来解决此问题。 Eg: 例如:
SELECT * FROM `book` join `journal`
WHERE `book`.`book-category` LIKE '$maincat2'
AND `book`.`book-category` LIKE '$subcat2'
AND `book`.`book-category` LIKE '$country2'
AND `book`.`book-category` LIKE '$procat2'
Maybe it's me but your query as it is doesn't make much sense to me. 也许这是我,但你的查询对我来说没有多大意义。
Probably you wanted something like this (using UNION
instead of JOIN
) and if, as you said, table schemas actually are the same for book
and journal
可能你想要这样的东西(使用UNION
而不是JOIN
),如果你说的话,表格模式实际上与book
和journal
相同
SELECT 'book' type, b.*
FROM book b
WHERE book-category LIKE '$maincat2'
AND book-category LIKE '$subcat2'
AND book-category LIKE '$country2'
AND book-category LIKE '$procat2'
UNION ALL
SELECT 'journal', j.*
FROM journal j
WHERE book-category LIKE '$maincat2'
AND book-category LIKE '$subcat2'
AND book-category LIKE '$country2'
AND book-category LIKE '$procat2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.