Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping and ordering

Status
Not open for further replies.

BB101

Programmer
May 23, 2001
337
GB
SELECT q.q_id, q.user_id, IF (e.firstname IS NULL , q.name, e.firstname) AS name, t.town, e.type, e.trading_name, e.posts
FROM qa_uk q
LEFT JOIN ayn_experts e ON e.unique_id = q.user_id AND e.active = 1
LEFT JOIN ayn_towns t ON t.id = q.town_id
WHERE q.active =1 AND t.town IS NOT NULL
GROUP BY q.user_id, q.name, q.town_id
ORDER BY q.datetime DESC

This query runs, however the field that comes back from the aggregate functions for the q fields is the first field in the database matching all others, how do i make it the last?

--BB
 
have a look at this --

13.9.3 GROUP BY with Hidden Fields

Do not use this feature if the columns you omit from the GROUP BY part are not unique in the group! You will get unpredictable results.

make sure that you are grouping correctly, i.e. on the right columns

consider the MIN() function for the those columns that are not unique within the groups

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top