Jump to content

Left join confusion


rockinaway

Recommended Posts

I have a normal query for the database and I was to do a left join. However, the data in this left join needs to be ordered first and only the latest values take (i.e. only one value taken).

 

I'm confused if I can include an order by for the left join and a where clause with it as well.

 

Would it be better to just have another query?

Link to comment
Share on other sites

Okay, I've worked on it, and it's having the desired effect currently, but I want to check the query is doing what I hope it is:

 

$query = 'SELECT t.mind, m.id, m.first_name, m.last_name
											FROM users AS m
											LEFT JOIN minds AS t ON t.u_id = m.id
					       					WHERE m.email = "'.$email_sent.'"
					       					ORDER BY t.time DESC LIMIT 1';

 

So I want to collect data from the users table for that one user. And then I want to get the information from the minds table. In the minds table, each user has several rows and so I want to order them in descending order by their time and then take the first one and add it to the rest of the user data..

 

 

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.