Jump to content

Not sure how to approach this query


sciencebear

Recommended Posts

I have a table I want to select from twice. It's called updates and I first want to select all updates where the username is equal to a variable $username. Second, in the same table, I want to select again from the table each update whose id matches the id in a second table, comments, where friendname is equal to the same variable $username. I then want to order all of these by id. I tried a few variations on JOINs but couldn't get it to work quite the way I wanted. I was thinking maybe something with a UNION but I couldn't figure out a working syntax for that either. Any suggestions?

Link to comment
Share on other sites

I'm not sure if I'm fully understanding what your after, it sounds like you want something along the lines of...

 

SELECT u.*, c.* FROM updates u JOIN comments c ON u.username=c.friendname WHERE u.username=$username

 

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.