Y
Y
Yuriy Berg2016-10-19 11:41:03
MySQL
Yuriy Berg, 2016-10-19 11:41:03

SQL insert a column from another table, how to write a condition?

Hello.
I have 2 tables
One is called images
4230e6ba9f1a4b448d42d4119d5426e0.png
Another products
e905c6ed9971453187fcce547bd05e16.png
The task is to transfer the url column (links to the image) from the images table to the products table in the (images) field in the picture it is not visible.
But you need to transfer with the condition that images.object_id be equal to products.id and images.object = "product"
I try to do this:

SELECT url, object_id FROM images INNER JOIN products ON images.object_id = products.id AND images.object = "product"

I don't know much about SQL queries, but something like this.
Can you at least just advise what to use here? Or read an article on how to use JOIN with conditions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2016-10-19
@art_haacki

SELECT  url, object_id 
FROM images 
INNER JOIN products ON images.object_id = products.id 
WHERE images.object = "product"

in JOIN only fields on which we unite. Conditions - in WHERE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question