# Thread: Simple query with GROUP BY question

1. ## Simple query with GROUP BY question

Hello,

Imagine this simples query:

Code:
```select 1 as A, 'test1' as B, '' as C

union

select 1 as A, '' as B, 'test2' as C```
this returns :

Code:
```---------------------
| A |   B   |   C   |
---------------------
| 1 | test1 |       |
---------------------
| 2 |       | test2 |
---------------------```
But I want to get:

Code:
```---------------------
| A |   B   |   C   |
---------------------
| 1 | test1 | test2 |
---------------------```
I tried doing something like:

Code:
```select t.A, t.B, t.C
from
(
select 1 as A, 'test1' as B, '' as C

union

select 1 as A, '' as B, 'test2' as C
) as t
group by t.A, t.B, t.C```
But that doesn't work.. How can I do this?

2. Code:
```SELECT t.A, MAX(t.B), MAX(t.C)
FROM ( SELECT 1 AS A, 'test1' AS B, '' AS C
UNION ALL
SELECT 1 AS A, '' AS B, 'test2' AS C
) AS t
GROUP
BY t.A```

3. Originally Posted by r937
Code:
```SELECT t.A, MAX(t.B), MAX(t.C)
FROM ( SELECT 1 AS A, 'test1' AS B, '' AS C
UNION ALL
SELECT 1 AS A, '' AS B, 'test2' AS C
) AS t
GROUP
BY t.A```
Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•