前几天我就这样设置了我的查询
$query = "SELECT card_id,title,description,meta_description,seo_keywords,price
FROM cards,card_cheapest order by card_id";
如您所见,我从表中选择了
card_id,title,description,meta_description,seo_keywords
,价格来自cards
。它们都有共同的cheapest_card
(在两个表中)。但是,我遇到了一个小问题。当我在navicat lite中运行查询时,收到一个错误card_id
。我做错什么了吗? 最佳答案
当两个或多个表有一个名称相同的列时,您必须限定希望该列来自的表。
即。:
$query = "SELECT cards.card_id,title,description,meta_description,seo_keywords,price
FROM cards,card_cheapest order by card_id";
此外,您真的想以这种方式运行查询,而不使用WHERE/JOIN子句来定义如何连接这两个表吗?
$query = "SELECT cards.card_id,title,description,meta_description,seo_keywords,price
FROM cards,card_cheapest WHERE cards.card_id = card_cheapest.card_id
ORDER BY card_id";
关于php - 从多个表中选择与mysql,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6059364/