Jump to content

MYSQL Cross Join


jaymc

Recommended Posts

Im trying to do a CROSS JOIN as shown below

 

My issue is inside the CROSS JOIN code it will not process this value  t.id which is part of the initial table

 

How can I allow the CROSS JOIN to use field values from the primary table I'm querying?

 

 

SELECT t.id, t.subject, t.department, tm.date
		FROM fred.client_tickets t

		CROSS JOIN (
			SELECT date
			FROM fred.client_ticket_messages
			WHERE tm.ticketID = t.id // HERE IS ISSUE, IT SAYS UNKNOWN t.id
			ORDER BY tm.date DESC
			) tm

		WHERE t.clientID = '$client[id]'
		GROUP BY t.id
		ORDER BY tm.date DESC

Link to comment
https://forums.phpfreaks.com/topic/165373-mysql-cross-join/
Share on other sites

 

 

SELECT t.id, t.subject, t.department, tm.date
		FROM fred.client_tickets t

		CROSS JOIN (
			SELECT date, ticketID
			FROM fred.client_ticket_messages
			ORDER BY date DESC
			) tm
		ON (tm.ticketID = t.id )

		WHERE t.clientID = '$client[id]'
		GROUP BY t.id
		ORDER BY tm.date DESC

 

Link to comment
https://forums.phpfreaks.com/topic/165373-mysql-cross-join/#findComment-872167
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.