如下图所示,我有两个表,现在我想根据Restaurant
列获取cat
表中的所有列,以及来自Foods
表的具有该Restaurant id的记录数
示例:(从Restaurant
表中获取 1,测试,从Foods
表中获取 3 )。
$sql = "select * from Restaurant,Foods where cat=6..." ;
更新:
$sql = "r.*,(SELECT COUNT(*) FROM restaurant_foods WHERE restaurant_id = r.id)
foods_count FROM restaurant r WHERE r.cats LIKE '%,$cat,%' limit $start,$end"
答案 0 :(得分:1)
那应该做的工作:
SELECT r.*,
(SELECT Count(*)
FROM Foods
WHERE restaurnat_id = r.id) foods_count
FROM Restaurant r
WHERE r.cat = 6