通过一个字段从另一个表中选择一个表中的行 [英] Selecting rows from a table by One a field from other table

查看:43
本文介绍了通过一个字段从另一个表中选择一个表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是显示由其他表单个值中的字段选择的表中的行,可以说按最后一个类别 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)

这篇关于通过一个字段从另一个表中选择一个表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆