How can I define a string with all unique field values ​​in MySql with PHP?

I am really trying to get this required output ... Any help would be appreciated.

I have a database like this in MySql:

  column_a          column_b     

int_value_1      string_value_1
int_value_2      string_value_2
int_value_3      string_value_3
int_value_4      string_value_4
int_value_5      string_value_5
int_value_6      string_value_6

      

... and as a result I require below:

A string or multiple rows that have unique values ​​in each column. This row must be unique in every field with every column.

Something like that:

      column_a                   column_b

1st_unique_int_value      1st_unique_string_value
2nd_unique_int_value      2nd_unique_string_value

      

Now the above rows / rows are completely unique for every field in every column.

I tried GROUP BY

, DISTINCT

and ARRAY_DIFF

, but could not complete this task. Please tell me if you are one of the experts in PHP and MySql programming and can help me along with the demo, as I am a bit new to this exciting world of programming and development.

+3


source to share


1 answer


Try this .. works



       select * from (
       SELECT col1,col2 FROM `table` group by `col1` having count(col1)=1)x
        JOIN ( SELECT col1,col2 FROM `table` group by `col2` having count(col2)=1
         )y ON x.col1 = y.col1 and x.col2=y.col2

      

+2


source







All Articles