Jump to content

[SOLVED] Table Comparison


PHPNS

Recommended Posts

Hi All,

 

I'm selecting information from two MySQL tables using a UNION query.  The data output will be in a list format.  A snippet is as follows:

 

$query = "select cl_id, cl_status from clients_confirm UNION select cl_id, cl_status from clients ORDER BY cl_id";		
$result = @mysql_query ($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo $row['cl_status']'<br />';

}

 

There are some rows (purposely) that will have the same number(id) from both tables (e.g cl_id from clients_confirm & cl_id from clients).  Here is a sample list output:

 

1 cl_status

2 cl_status

2 cl_status  (don't want this second one... or maybe the first)

3 cl_status

4 cl_status

etc.

 

I need to find a way to choose only one of the id's when two of the same (one from each table) are selected.  In other words, I don't want duplicate rows echo'd.

 

Can someone please help??

 

Thanks.

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/79163-solved-table-comparison/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.