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 > One more SELECT question...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-04-04, 22:48
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
One more SELECT question...

Hi,

Given the query below (courtesy of roga)
Code:
SELECT *
FROM logins
LEFT JOIN profiles USING (some_id)
LEFT JOIN prefs USING (some_id)
LEFT JOIN avatars ON profiles.avatar_id=avatars.avatar_id
LEFT JOIN groups ON profiles.group_id=groups.group_id
LEFT JOIN tmpl ON prefs.tmpl_id=tmpl.tmpl_id
WHERE username='john'
I would like to add another clause to the query to count the number of rows from another table given certain conditions. On it's own, that new query looks like this:
Code:
SELECT COUNT(*) FROM message where username=sender
How do I append that to the group of LEFT JOINs query above? The COUNT(*) should only apply to the query on the 'message' table and not only the other tables.
Reply With Quote
  #2 (permalink)  
Old 01-06-04, 20:19
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
My solution is to have two separate SELECT statements for the two queries. Let me know if I'm missing something terribly obvious
Reply With Quote
  #3 (permalink)  
Old 01-06-04, 21:24
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
There 'ya go... why be "clever?" Just run two queries. If you need more, write a few more queries that work with the output from that. It's really easy to write a "write-only query," if you know what I mean.
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
  #4 (permalink)  
Old 01-07-04, 03:12
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
thanks, sundialsvcs!

it was more of a case of not knowing what my options are.

i had this funny idea that you try get as much as you can with a single query. i didn't know multiple selects for a related transaction was an option
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