0

I have got a website built on wordpress and would like to create a SQL query for displaying users points by their username.

Points in the table linked to users IDs and not to usernames. My SQL query is:

SELECT ID 
FROM wp_users 
WHERE user_login='{username}'

SELECT points 
FROM wp_cp 
WHERE uid=ID

Which is wrong. Separately they work fine but how can I make only one SQL query?

The logic should be by typing username - SQL gets its ID from wp_users and automatically points number from wp_cp by matching users ID.

Can anyone please help me with this problem? Thank you.

1
  • 2
    Have you missed the JOIN class? Commented Jan 9, 2014 at 10:52

1 Answer 1

1

here you hav a litle hint,

SELECT points 
    FROM wp_cp join wp_users 
    on wp_cp.uid=wp_users.ID 
    where wp_users.user_login ='username'

DISCLAIMER: I DIDNT TEST IT, this is just a hint!

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Melon. It is very close but still not working. ;-( Maybe because wp_cp has got column uid and wp_users has got column ID
try it now, it just missed the tablenames on colums. you can finish it from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.