如何结合这两个查询?

时间:2011-09-28 08:00:56

标签: php mysql

SELECT htpid AS parentid 
    FROM likehot WHERE htpid 
    IN (SELECT id FROM bultin WHERE  DATE  >= '1317108749') 
    GROUP BY htpid ORDER BY COUNT( htpid ) 
    DESC

给出结果

parentid
16060
16059
16058
16057

和其他查询

SELECT app_id,bultin.id,photo_album_id,entcmmnt_id,link_url,youtubeLink,
       link_image,id, mem_id, subj, body, bultin.date,parentid, 
       from_id, visible_to, image_link,post_via 
FROM bultin 
WHERE id IN ('16062','16059','16058','16057') 
ORDER BY FIELD('16062','16059','16058','16057') 
LIMIT 5

实际上我想要与IN中相同的序列,所以我使用了FIELD运算符

请建议 感谢

2 个答案:

答案 0 :(得分:0)

我无法理解你的问题..如果你可以请解释一下更好的方式..我可以给你解决方案..我想说你不能在第一个方面使用超过一个值查询“SELECT id FROM bultin WHERE DATE> ='1317108749')”。还有一件事Y你不使用ist查询中的值,就像这样

SELECT htpid AS parentid     来自likehot WHERE htpid     IN(16062','16059','16058','16057')

答案 1 :(得分:0)

如果我没有错过任何内容,这应该可以胜任:

SELECT b.app_id, b.id, b.photo_album_id, b.entcmmnt_id, b.link_url, b.youtubeLink,
    b.link_image, b.mem_id, b.subj, b.body, b.date, b.parentid,
    b.from_id, b.visible_to, b.image_link, b.post_via
FROM bultin AS b
JOIN (
    SELECT htpid, COUNT( htpid ) AS htpid_count
    FROM likehot
    GROUP BY htpid ORDER BY COUNT( htpid )
    DESC
) AS l ON l.htpid = b.id
WHERE DATE  >= '1317108749'
ORDER BY l.htpid_count
LIMIT 5

如果您需要有关此查询的更多详细信息,请与我们联系。