Page 1 of 1

ordering from another table

Posted: Fri Nov 07, 2008 12:09 pm
by m2babaey
Hi
i have offers table that contain a field as the user_id
and member table with the field "membertype" ( 1 , 2 or 3 )
I want to list the offers ordered by user type (gold type's offers are shown first)
solutions:
1. adding the membertype field to offer table when posting an offer
etc.
do you think this is the best (easiest and fastest) way?
thanks for your notes

Re: ordering from another table

Posted: Fri Nov 07, 2008 12:15 pm
by veridicus
It's best to keep the information in two separate tables. A membership table would contain all membership information. When you need that information for sorting, join back to that table and use it in an ORDER BY clause.

Re: ordering from another table

Posted: Sat Nov 08, 2008 3:34 am
by m2babaey
thanks. I used join and it worked.
1 other thing is how we can do ordering based on 2 fields. that means for example all data from membertype=1 is shown then membertype=2 etc but each group is ordered by their id (or submission date DESC)? how would the order clause be then?
thanks for your help

Re: ordering from another table

Posted: Sat Nov 08, 2008 5:50 am
by Mark Baker
m2babaey wrote:1 other thing is how we can do ordering based on 2 fields. that means for example all data from membertype=1 is shown then membertype=2 etc but each group is ordered by their id (or submission date DESC)? how would the order clause be then?
thanks for your help

Code: Select all

 
SELECT A.*
  FROM table1 A,
       table2 B
 WHERE A.column1 = B.column2
 ORDER BY A.column1,
          B.column3 DESC