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