ordering from another table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

ordering from another table

Post 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
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Re: ordering from another table

Post 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.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Re: ordering from another table

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: ordering from another table

Post 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
 
Post Reply