0

so i have this query

select oldvalue, newvalue from(select 'a' as oldvalue, 'b' as newvalue) as N

now the problem is i can only have 1 value each column when i want to have multiple value in column, i have tried using union all like this

select oldvalue, newvalue from(select 'a' as oldvalue, 'b' as newvalue UNION ALL 'c', 'd') as N

with this now i have a and c as oldvalue and b and d as newvalue, but with union all i can only have 2 max of value in each column, is there a way for me to have more than two value in each column

6
  • The number of columns which can appear in a select is not limited to 2. Can you better explain what you are trying to do? Commented Dec 27, 2019 at 4:17
  • i want to make temporary table with 2 column, and each column can have multiple value, i want to add a value in a column not add another column Commented Dec 27, 2019 at 4:18
  • 4
    You're missing a SELECT immediately after UNION ALL. Commented Dec 27, 2019 at 4:18
  • @TimBiegeleisen oh okay, one last question, can i have multiple union all select? like more than one union? Commented Dec 27, 2019 at 4:22
  • 1
    Yes, you can do that. Note that you don't need to repeat the alias you define in the very select in the union. Subsequent aliases will in fact just be ignored anyway, only the first one matters. Commented Dec 27, 2019 at 4:23

1 Answer 1

1

Just writing in CODE what @TimBiegeleisen has mention in the comment.

  SELECT oldvalue, newvalue 
  FROM ( SELECT 'a' as oldvalue, 'b' as newvalue UNION ALL 
       SELECT 'c', 'd' UNION ALL
       SELECT 'e' ,'f' UNION ALL
       SELECT 'g' ,'h' UNION ALL
       SELECT 'i','j' ......
      ) as N
Sign up to request clarification or add additional context in comments.

Comments

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.