SELECT
*
FROM
".DB_PREFIX."ticket t
LEFT JOIN
".DB_PREFIX."ticket_c c
ON
c.ticketID = t.ticketID
WHERE t.requesterID = '".$id."' ";
ORDER BY
c.commentDate DESC
Hi,
I’m trying to use JOIN to get variables from 2 tables. Currently I have (as above)
It seems to return everything fine, but will only return the first ticketID. The main data is from ticket, with the ORDER BY relying on ticket_c
Does anyone know where I’m going wrong? I’m new to JOINs
query looks fine (apart from the dreaded SELECT *, but)… are you sure there’s extra data that should be returned? (IE: the requesterID in question has multiple entries in the ticket table?)
Unnecessary, probably. More readable, you better believe it. But that is beside the point I guess.
The advice I give TacMaf is to make sure the data comes out exactly like you want it by running the SQL code in MySQL Query Browser or phpMyAdmin. If it does, then in PHP or whatever language you are using, fetch your data into an array and then print_r() it so you can see what it looks like. Hopefully it will be easy to figure it out from there.