If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Converting a subquery into a join query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-31-06, 01:17
rexselin rexselin is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 109
Converting a subquery into a join query

I have a subquery which does not work in the mysql version that my client has installed.

[SQL]
SELECT user_name from users
where user_id in
(select poster_id
from posts
order by post_created_on
desc limit 0,10)
[/SQL]

How to convert this into a query with join?

I tried the below syntax and it doesnt work.

select user_name from users, posts where users.user_id=posts.poster_id
group by posts.poster_id order by post_created_on
desc limit 0,10
Reply With Quote
  #2 (permalink)  
Old 07-31-06, 01:52
rexselin rexselin is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 109
No problem. I tried this and it seems to work.

SELECT user_name,
max( unix_timestamp( poll_created_on ) ) AS mx
FROM users
INNER JOIN posts ON users.user_id = posts.poster_id
GROUP BY user_name
ORDER BY mx DESC
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On