skip to Main Content

i am trying to display some data about a specific id and THATS where the WHERE Clause comes in place, but it doens’t work.
By the way in wp_posts the user_id is the wp_users.ID.

SELECT wp_users.ID, post_name FROM wp_users
LEFT JOIN wp_posts
ON wp_users.ID = user_id
ORDER BY wp_users.ID
WHERE wp_users.ID="2"

This works and displays the wp_users.ID and post_name but if i want to display only the post_names of a specific ID with this line ‘WHERE wp_users.ID="2"’ it doesn’t work.

New to MySQL

2

Answers


  1. Chosen as BEST ANSWER

    Nevermind it works now

    SELECT wp_users.ID, post_name 
    FROM wp_users
    LEFT JOIN wp_posts ON wp_users.ID = user_id
    WHERE wp_users.ID="2"
    

  2. I’ll try to fix the query for you, in some way that makes sense to me:

    SELECT A.ID, B.post_name 
    FROM wp_users A
      LEFT JOIN wp_posts B ON A.ID = B.user_id
    WHERE A.ID='2'
    ORDER BY B.ID
    

    Assuming:
    table wp_users(ID,…) ID is Primary key
    table wp_posts(ID, user_id,…) ID is Primary key and user_id is foreign key references wp_users(ID)
    A and B are alias… I alwais use them (and DBMS also loves them).

    Hope it helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search