0

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.

1
  • thats a simple string concatenation Commented Mar 1, 2013 at 10:01

2 Answers 2

1
INSERT INTO Table_A (Col1, Col2)
VALUES ('Input1', CONCAT_WS('|', 'Input2', 'Input3', 'Input4'))
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

thank you for your help, but now i have another problem, wich is that i should Insert the Inpu1 one into Col1 with a prefix, so if the value of input1=50 i want to insert it in col1 like this "IC-50" with the prefix IC
@user2122969 "IC-" common for all field of database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.