D
D
Dmitry2015-12-07 10:17:31
MySQL
Dmitry, 2015-12-07 10:17:31

How to perform SELECT and INSERT in the same query?

Guys, help me make a request to the database, I can’t finish it myself!
There is a table with products in which the columns are: ID (product id), Article (article), SKU (matches the article), IMG (image link).
You need to make such a request so that the article is written to the IMG column in this form: "/catalog/images/'article'.jpg".
Accordingly, each line has its own article and exactly the same should be recorded in the IMG.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-12-07
@koteich

Use concat()
update tbl_name set img = concat("/catalog/images/", article, ".jpg".)

H
hostwell, 2015-12-07
@hostwell

As far as I'm concerned, it's completely useless. Firstly, why write /catalog/images/ to the database at all - this path can be substituted when outputting, and you do not need to store extra text in the database. And if the name of the picture matches the article, then why store the name. It is better to make sure that all pictures have the same file extension and that's it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question