Reputation: 111
I am really new to SQL, and I have this little problem :
I Have a page with many inputs, let's say
Input1, Input2, Input3, Input4
And I have a a table
TABLE_A
Col1
Col2
Col3
What I want to do is to insert Input1
into Col1
(which is a simple thing), and to insert all of the other inputs (2,3 and 4 ) into Col2
separated by a SPACE OR a "|"
If anyone can help that would be wonderful.
Upvotes: 0
Views: 1774
Reputation: 8084
Checkout String Functions which gave you brief knowledge about separated by "SPACE" OR "|" OR ",".
In that above link check some functions with examples which help you in future also.
CONCAT_WS()
Return concatenate with separatorCONCAT()
Return concatenated stringELT()
Return string at index numberEXPORT_SET()
Return a string such that for every bit set in the
value bits, you get an on string and for every unset bit, you get an
off stringFIELD()
Return the index (position) of the first argument in the
subsequent argumentsFIND_IN_SET()
Return the index position of the first argument within
the second argumentUse CONCAT()
to insert different input values into one column.
INSERT INTO Table_A (Col1, Col2)
VALUES ('Input1', CONCAT('|', 'Input2', 'Input3', 'Input4'))
may this help you.
Upvotes: 1
Reputation: 49049
INSERT INTO Table_A (Col1, Col2)
VALUES ('Input1', CONCAT_WS('|', 'Input2', 'Input3', 'Input4'))
Upvotes: 1