通过一个字段从另一个表中选择一个表中的行
问题描述:
我想要的是显示由其他表单个值中的字段选择的表中的行,可以说按最后一个类别 ID 显示表中的图像.
What i want, to display rows from a table which is selected by a field from other table single value, lets say to display images from a table by last category id.
我有这种类型的查询,但这会返回所有匹配的键行,如果我插入 LIMIT 1 那么它会返回一行...
I have this type of query, but this return me all matching keys rows, if i inset LIMIT 1 then it return one row...
SELECT i.prof_image FROM profile_images i
JOIN images_cat cat ON (cat.cat_id = i.cat_id)
GROUP BY i.prof_image;
//OR LIMIT 1;
解决这个问题的任何想法.(即显示最新的类别图片)?
Any idea to fix this problem. (i.e. displaying the latest category images)?
答
这将适用于您的具体示例.. 如果您需要更具选择性,请发布更多详细信息..
This will work for your specific example.. If you need to be more selective, then please post some more details..
SELECT i.prof_image
FROM profile_images i
WHERE cat_id = (select max(cat_id) from images_cat)