Gossamer Forum
Home : General : Databases and SQL :

Help with ORDER BY and expressions?

Quote Reply
Help with ORDER BY and expressions?
I'm trying to extend the code :

SELECT uid, affiliate_uid FROM user ORDER BY affiliate_uid

To bring back all matching results but first listing rows where user.affiliate_uid=$affid and then listing all remaining results (where $affid is not necessarily the maximum or the minimum value $affid can take).

Any pointers would be welcome.

Many thanks,

C
Quote Reply
Re: [ctimms] Help with ORDER BY and expressions? In reply to
What database server are you using? It will help to know since sub-queries may work, but only in certain database servers and versions.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Help with ORDER BY and expressions? In reply to
I'm using primebase (www.snap.de) but I'd accept any answer which works with mysql....

Since the posting I've come up with :

SELECT uid, affiliate_uid, (affiliate_uid-$affid)*(user.affiliate_uid-$affid) FROM user ORDER BY 3

But I'm thinking it can't be the most efficient code out there - do you know of anything out there which might be more efficient?

C
Quote Reply
Re: [ctimms] Help with ORDER BY and expressions? In reply to
In MySQL you can do:

SELECT uid, affiliate_uid
FROM user
ORDER BY affiliate_uid <> $affid

Cheers,

Alex
--
Gossamer Threads Inc.