我的目标是通过特定匹配获得两个或更多结果。我试过这个:
SELECT * FROM edgewe_ngg_pictures a, edgewe_ngg_gallery b WHERE galleryid=("555","556") limit (1,1)
期待获得2场比赛,但是我收到了一个错误。有什么想法吗?
澄清:我想从每个画廊获得一个结果。
答案 0 :(得分:0)
看起来您需要使用IN代替=。
SELECT *
FROM edgewe_ngg_pictures a, edgewe_ngg_gallery b
WHERE galleryid IN ("555","556")
limit 2
编辑:
根据您的评论判断我认为以下是您的意见。它应该得到555的一个结果和556的一个结果。
(SELECT *
FROM edgewe_ngg_pictures a, edgewe_ngg_gallery b
WHERE galleryid = "555"
limit 1)
UNION ALL
(SELECT *
FROM edgewe_ngg_pictures a, edgewe_ngg_gallery b
WHERE galleryid = "556"
limit 1)
答案 1 :(得分:0)
除了错误之外你不应该添加一些连接标准吗?
SELECT *
FROM edgewe_ngg_pictures a
inner join edgewe_ngg_gallery b on a.galleryid = b.galleryid
WHERE b.galleryid IN ("555","556")
否则你总是选择所有图片(假设galleryid是b的一列)
更新:
SELECT *
FROM edgewe_ngg_pictures a
inner join edgewe_ngg_gallery b on a.gid = b.galleryid
WHERE a.id in (select min(id)
from edgewe_ngg_pictures p
where gid in ("555","556") group by gid)