0

I need to query the database to pull all cars that a particular user likes.

I know that user_id is 1

Then I have 2 tables. 1 contains all the cars ... id and description and table 2 contains the likes.

Table 1 has a list if cars and these fields:

car_id
car_name,
car_description


Table 2 has what cars I like and these fields:

user_id
car_id
likes (1 or 0)

So I need to pull out only the records that user 1 likes from Table 2 but only the ones he likes

What SQL query would I need to do for that?

0

3 Answers 3

2
SELECT * FROM table1 as t0
LEFT JOIN table2 as t1 on t0.car_id = t1.car_id
WHERE t1.likes = 1
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

SELECT * FROM table1 as t1 LEFT JOIN table2 as t2 on t1.car_id = t2.car_id WHERE t2.user_id = $user_id

Comments

0

Try this query

SELECT t1.*,t2.*
FROM tbl1 t1,tbl2 t2
WHERE likes = 1 AND user_id = 1 AND t1.car_id = t2.car_id

Comments

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.