0

I have two tables products and users with fields,

Products

id
name
insertedUserID
ipdatedUserID

Users

id
name

I am trying to get the the product details with the data,

ProductID
ProductName
InsertedUser
UpdatedUser

For this I am using this mysql query,

SELECT Products.id as ProductID,Products.name as ProductName, Users.name as InsertedUser 
LEFT JOIN Users ON Products.insertedUserID = Users.id

This query is working only for Inserted user only. How can I get updated user with this query?

0

1 Answer 1

0

I am not sure you want to get both data or and condition so . if you want to both condition data then use union all

SELECT Products.id as ProductID,Products.name as ProductName, Users.name as InsertedUser 
LEFT JOIN Users ON Products.insertedUserID = Users.id

union all 
SELECT Products.id as ProductID,Products.name as ProductName, Users.name as InsertedUser 
LEFT JOIN Users ON Products.ipdatedUserID = Users.id

or if you want to only single condition then

SELECT Products.id as ProductID,Products.name as ProductName, Users.name as InsertedUser 
    LEFT JOIN Users ON Products.insertedUserID = Users.id and Products.ipdatedUserID = Users.id

hope it will help you

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

1 Comment

I suspect what is needed here: LEFT JOIN Users ON Products.insertedUserID = Users.id and Products.ipdatedUserID = Users.id is "OR", not "and".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.