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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.