K
K
kevus2018-06-26 19:42:34
MySQL
kevus, 2018-06-26 19:42:34

How to add such a SQL query?

Hello.
There is this SQL query:

INSERT INTO db (name,f,link,time) VALUES ('%name%','%price%','%link%','%date%');

(name - PRIMARY KEY)
The task is this. Supplement the query in such a way that new data would be added to "f" and "time", not overwritten with new ones, but just added.
For example, the first request
is f=text1
time=15:58:00
The second
f=text2
time=15:59:00
The result
is f=text1|text2
time=15:58:00|15:59:00
Thank you!
ps: I know that date \ time do not accept this format. They have an attribute in my case VARCHAR.
And in general, you know that it’s not the best structure for storing data, but it’s necessary :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Nemiro, 2018-06-26
@kevus

Probably something like this:

INSERT INTO db (name, f, link, time) VALUES ('%name%', '%price%', '%link%', '%date%') 
ON DUPLICATE KEY UPDATE f = CONCAT_WS('|', f, '%price%'),  time = CONCAT_WS('|', time, '%date%')

S
Stanislav Pugachev, 2018-06-26
@Stqs

kevus ,
how is it?

INSERT INTO db (name,f,link,time) VALUES ('%name%','%price%','%link%','%date%') 
    ON DUPLICATE KEY UPDATE f=CONCAT_WS('|', f, '%price%');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question