I have a table with several columns that have repeated values. I want to select and list only the unique values from 2 columns and list them alternately.
This code works as expected to select unique vales from column 'listing_location' where area column is 'area1' and list them:
And the same code works for column 'business_category'
But when I try and combine the 2, like this:
The values get repeated. Seems that distinct values are now only recognised as one where the *combination* of business_category and listing_location are unique.
Is there an easy way to do what I want with a single query, or do I need to do 2 separate queries and build a string to display the values alternately? And if the latter, how do I do this?
Thanks.
This code works as expected to select unique vales from column 'listing_location' where area column is 'area1' and list them:
Code:
$query = " SELECT DISTINCT listing_location FROM listings WHERE area = 'area1' LIMIT 10";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo (", {$row['business_category']");},
And the same code works for column 'business_category'
But when I try and combine the 2, like this:
Code:
$query = " SELECT DISTINCT business_category, listing_location FROM listings WHERE area = 'area1' LIMIT 10";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo (", {$row['business_category']}, {$row['listing_location']}");}
The values get repeated. Seems that distinct values are now only recognised as one where the *combination* of business_category and listing_location are unique.
Is there an easy way to do what I want with a single query, or do I need to do 2 separate queries and build a string to display the values alternately? And if the latter, how do I do this?
Thanks.