Say you have 3 tables

A (Key, a)
B (Key, b)
C (Key, c)

How would you select say 10 from A ordered by a, from 50 from B ordered by b, from 100 from C ordered by c? All the keys represents the same thing.

Thanks!

Recommended Answers

All 4 Replies

What is 10, 50 and 100? See if you are looking for UNION.

the top 10 etc once ordered

Did you look at UNION?

SELECT X.key, coalesce(a,0) AS ao, b FROM B RIGHT JOIN 
(SELECT * FROM B ORDER BY b LIMIT 0 , 100) AS X
ON B.key = X.key ORDER BY ao desc LIMIT 0, 50

is what I ended up with (I think...). This takes the top 100 once ordered by b, from which the top 50 are taken once ordered by a (I think... might have been a different JOIN, can't remember or be bothered to look).

I didn't look at UNION, maybe there's a neater solution. It seemed a bit long winded for such a common task.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.