S
S
Sergey Sova2014-04-30 17:31:52
MySQL
Sergey Sova, 2014-04-30 17:31:52

How to select from two MySQL tables?

I have two tables
product (id, name, price, description)
wishlist (product_id, user_id)
I need to select all records from the product table and add the key `inlist` 1 or 0, depending on whether there is a record with wishlist.product_id =product.id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kfuntov, 2014-04-30
@LestaD

SELECT
    p.*,
    NOT ISNULL(wl.product_id)
FROM product as p
LEFT JOIN wishlist as wl ON p.id = wl.product_id;

UPDATE thanks @AxisPod

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question