Jump to content
xisto Community
Sign in to follow this  
dolrich06

Problem With Order By Sql Statement

Recommended Posts

How can i order them by the most number of attractions or most number of rewards? :lol:

Tables

member table - the main table

member_id  | name1				  dolrich2				  test3				  sampleattraction table attraction_id | member_id 1				12				23				24				35				36				37				3

What i want is that i can order by them by their number of attractions

Here is the result expected.

member_id	  attractions count3						   42						   21						   1


Here is the query for counting the number of attractions and rewards of each member.

SELECT  a.member_id, count(b.member_id) as attractions, count(c.member_id) as  rewards  FROM member a LEFT OUTER JOIN attraction b ON a.member_id = b.member_id						   LEFT OUTER JOIN  reward c ON a.member_id = c.member_id  GROUP BY a.member_id

Edited by dolrich06 (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.