Usman Saeed
Usman Saeed

Reputation: 15

Murge 2 columns Table data in 1 column of Combobox

I have a combo box and a table MyTable MyTable:

ID ¦ A ¦ B ¦
-------------
1  ¦ 1 ¦ 4 ¦
2  ¦ 2 ¦ 5 ¦
3  ¦ 3 ¦ 6 ¦

I have managed to get values in combobox like this.

Row Source = select A, B from MyTable

Relult:

1 ¦ 4
2 ¦ 5
3 ¦ 6

But i want to murge these 2 columns in one column and want to show like this.

Output:

1
2
3
4
5
6

I am sorry if its a repeated question but i have searched for my answer and didn't find my solution

Upvotes: 0

Views: 42

Answers (4)

bjeftic
bjeftic

Reputation: 66

You can add ORDER BY ASC at the end, to be sure if the data are not arranged in the order in the table.

select a as 'a-b' from MyTable union select b as 'a-b' from MyTable order by 'a-b' asc

Or demo.

Upvotes: 1

Andy3B
Andy3B

Reputation: 454

DECLARE     @MyTable    TABLE   (ID int, A int, B int)
INSERT INTO @MyTable    VALUES
            (1, 1, 4)
        ,   (2, 2, 5)
        ,   (3, 3, 6)

SELECT  Output = A  FROM @MyTable
UNION
SELECT  Output = B  FROM @MyTable

Upvotes: 1

Usman Saeed
Usman Saeed

Reputation: 15

I have managed to get my solution using VN'sCorner solution

Row Source = select A as Colmn from MyTable
Union All
select B as Colmn from MyTable

And boom i have an output Output:

1
2
3
4
5
6

Upvotes: 0

VN'sCorner
VN'sCorner

Reputation: 1552

Use Union All, Query will be as below:

select A as Colmn from MyTable
Union All
select B as Colmn from MyTable

Upvotes: 1

Related Questions