开发者

How to combine these two queries?

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

giving result

parentid
16060
16059
16058
16057

and other query

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

Actually I wanted the same sequence as that of in IN so I used FIELD operator

Please Suggest thanks


I couldn't Understand Your Question.. If You Can Please Explain it a better way.. I can gave you the Solution.. Wel I would like to say that u can not use more then one value in side the First Query "SELECT id FROM bultin WHERE DATE >= '1317108749')". And One more thing Y don't u use the values in the ist query like this

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


If I haven't miss anything, this should do the job:

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

Let me know if you need more details about this query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜