Subject: Re: newbie: ORDER BY From: "J West" Date: Mon, 3 Jan 2005 17:49:16 -0000 Newsgroups: mailing.database.mysql There are loads of different way's of doing this and everyone has their own preference but the answer is very simple. I would use a join and an orderby clause but this would very much depend on the size of the tables and the database I was using. For MSSQL I might use a stored procedure and do it in stages or for large quantities of data and if this is a routine I would use a lot I might consider setting up a table view! Also your select doesn't actually make a great deal of sense! What benefit will you gain from having a list of user ID's sorted in a seemingly random order? (See assumption below) I have to make the assumption that you are wanting a list of unique user id's that exist in the booking table but want to order this list by a field other than the user id in the user table. I also have to make the assumption that the buid you refer to is a foreign key linking to a field in the user table of the same type and it is probably called something like UserID. If this is not the case what you are trying to do is impossible. But to answer the question you have asked, whatever you do you have to link the two tables together I would probably do something like SELECT u.UserID, e.buid FROM User u LEFT OUTER JOIN e.bui = u.UserID ORDER BY u.AField This will give you what you have asked for (I think the actual syntax should work but you would need to change the field names to match) Regards James West "John" wrote in message news:10tigb5g7dt2m98@corp.supernews.com... >> >> Hi, >> >> I am new to databases, so I may not understand enough to know that >> I am asking the correct questions... >> >> I want to do a SELECT on a table, returning just 1 column, but sorted >> according to another column in the origianl table. >> >> Whats the general way to do this ? >> >> I have tried: >> >> SELECT DISTINCT buid FROM bookingtable ORDER BY user >> >> which does not seam to work. >> >> The other way I can think of to do it :- >> >> A 2 stage approach, >> >> first make a selection that also includes the column on which >> I want to order by, >> >> then make a selection from that with just the single column >> that I am really interested in. >> >> But I'm not sure how to do this. >> >> Can you run a second query on the results of the first ? >> >> Or do I have to create a new table (from the first query) to do that ? >> >> Thanks, >> John. >>