Jump to content

GROUP BY ORDER


jaymc

Recommended Posts

SELECT t.id, t.subject, t.department, tm.date
		FROM fred.client_tickets t
		INNER JOIN fred.client_ticket_messages tm
		GROUP BY t.id
		ORDER BY tm.date

 

ORDER BY tm.date becomes useless because of the GROUP BY

Link to comment
Share on other sites

Use MAX() or MIN() functions to select latest/earliest date.

 

That works on the individual field you apply MIN() or MAX() to but it does not pull put the entire row of the MAX(date)

 

The other fields are still random..

Link to comment
Share on other sites

I want to pull out a row from a table by its primary ID, then join another table which has multiple rows with the same ID as the primary, but not unique

 

table 1:

id-1

id-2

id-3

 

table 2:

ticketID-1

ticketID-1

ticketID-1

ticketID-2

ticketID-3

ticketID-3

 

Link to comment
Share on other sites

Hmm yes, although trying your example with new fields,database It does not work

 

Heres what I have got so far

 

	SELECT t.id, t.subject, t.department, tm.responder, tm.date
	FROM fred.client_tickets t 
	INNER JOIN
	(
		SELECT date, responder
		FROM fred.client_ticket_messages
		GROUP BY ticketID
	)
	AS tm USING ( date, responder )

 

Error: Unknown column 'date' in from clause

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.