Reputation: 153
I have 4 columns a, b c, d in my table (MySQL database) . I want to select the distinct values of ALL of these 4 columns in my table . More deeply my table is given bellow..
a b c d
--------------------------
1 3 3 4
1 2 3 0
1 1 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
In the above table (1,2,3,4) value are repeating 4 times(look the last 4 rows of my table). I want only the distinct one , ie i want to get the bellow table after mysql query..
a b c d
---------------
1 3 3 4
1 2 3 0
1 1 3 4
1 2 3 4
I think you guys got some idea . Im not familier with MySql .
Upvotes: 5
Views: 10471
Reputation: 6134
try this:
SELECT DISTINCT a FROM my_table
UNION
SELECT DISTINCT b FROM my_table
UNION
SELECT DISTINCT c FROM my_table
UNION
SELECT DISTINCT d FROM my_table
update 1:
SELECT a,b,c,d
FROM my_table
GROUP BY a,b,c,d;
http://sqlfiddle.com/#!2/c49ad/11
Upvotes: 0
Reputation: 11310
SELECT DISTINCT column_name,column_name FROM table_name;
I mean
select distinct a,b,c,d from table_name;
Here is the link of w3schools
Upvotes: 2