PaxBin
PaxBin

Reputation: 111

Inserting Different Input Values Into One Column (MySQL)

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

Answers (2)

Tony Stark
Tony Stark

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.

  1. CONCAT_WS() Return concatenate with separator
  2. CONCAT() Return concatenated string
  3. ELT() Return string at index number
  4. EXPORT_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 string
  5. FIELD() Return the index (position) of the first argument in the subsequent arguments
  6. FIND_IN_SET() Return the index position of the first argument within the second argument

Use 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

fthiella
fthiella

Reputation: 49049

INSERT INTO Table_A (Col1, Col2)
VALUES ('Input1', CONCAT_WS('|', 'Input2', 'Input3', 'Input4'))

Upvotes: 1

Related Questions