Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL getting distinct data from multiple columns?

Status
Not open for further replies.

Vaastav

Programmer
Nov 6, 2002
5
GB
Hi, I have got 4 columns with data in and I want select all the distinct data from each column and display it in a table. How do I go about doing this.

Heres an exmaple of what my Columns in my table are like:-
Column1 Column2
0 this is empty
this is empty 1
0 0
0 this is empty

Output should be something like this:-
0
1
0
0

Thanks for your help in advance.
 
Your question and example table are ambiguous. Given the following table:

[tt]+---------+---------+
| column1 | column2 |
+---------+---------+
| NULL | NULL |
| NULL | 0 |
| NULL | 1 |
| 0 | NULL |
| 0 | 0 |
| 0 | 1 |
| 1 | NULL |
| 1 | 1 |
| 1 | 1 |
| NULL | NULL |
| NULL | 0 |
| NULL | 1 |
| 0 | NULL |
| 0 | 0 |
| 0 | 1 |
| 1 | NULL |
| 1 | 1 |
| 1 | 1 |
+---------+---------+[/tt]

What do you expect the output to be? ______________________________________________________________________
TANSTAAFL!
 
+---------+---------+
| column1 | column2 |
+---------+---------+
| NULL | NULL |
| NULL | 0 |
| NULL | 1 |
| 0 | NULL |
| 0 | 0 |
| 1 | 1 |
| 1 | NULL |
| 0 | 0 |
+---------+---------+

The data in the table can either be the same i.e. 0 0 or 1 1 but not different values in each column for the same row.

This what I'm aiming for:-
0
1
0
0
1
1
0

Thanks
 
But NULL counts as matching either 1 or 0? ______________________________________________________________________
TANSTAAFL!
 
Its okay thanks for having a look at this. I think I've sussed it.

Vaastav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top