dbTalk Databases Forums  

Getting DISTINCT results from a union

comp.databases.mysql comp.databases.mysql


Discuss Getting DISTINCT results from a union in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bill
 
Posts: n/a

Default Getting DISTINCT results from a union - 11-13-2010 , 06:24 AM






I want to create a result set that contains the patient numbers
and episode numbers of patients that have had transactions or
payments in the prior month.

I figured that I would do a union of selects on the transaction
file and the payments file, making them distinct so that I only
get one ptNum, epiNum pair for each patient/episode that had one
or more transactions or payments.

But, when I do the union I might (and usually will) end up with a
2nd ptNum, epiNum for each patient/episode. While I can program
around this in the application I was wondering if I could do this
in MySQL so that I ended up with just one ptNum, epiNum pair.

-- Bill Drescher william {at} TechServSys {dot} com

Reply With Quote
  #2  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: Getting DISTINCT results from a union - 11-13-2010 , 06:35 AM






On Nov 13, 12:24*pm, bill <will... (AT) TechServSys (DOT) com> wrote:
Quote:
I want to create a result set that contains the patient numbers
and episode numbers of patients that have had transactions or
payments in the prior month.

I figured that I would do a union of selects on the transaction
file and the payments file, making them distinct so that I only
get one ptNum, epiNum pair for each patient/episode that had one
or more transactions or payments.

But, when I do the union I might (and usually will) end up with a
2nd ptNum, epiNum for each patient/episode. *While I can program
around this in the application I was wondering if I could do this
in MySQL so that I ended up with just one ptNum, epiNum pair.

-- Bill Drescher william {at} TechServSys {dot} com
A UNION is DISTINCT by default. You have to code UNION ALL to stop it
being DISTINCT.

Reply With Quote
  #3  
Old   
bill
 
Posts: n/a

Default Re: Getting DISTINCT results from a union - 11-14-2010 , 05:01 AM



On Nov 13, 7:35*am, Captain Paralytic <paul_laut... (AT) yahoo (DOT) com> wrote:
Quote:
On Nov 13, 12:24*pm, bill <will... (AT) TechServSys (DOT) com> wrote:

I want to create a result set that contains the patient numbers
and episode numbers of patients that have had transactions or
payments in the prior month.

I figured that I would do a union of selects on the transaction
file and the payments file, making them distinct so that I only
get one ptNum, epiNum pair for each patient/episode that had one
or more transactions or payments.

But, when I do the union I might (and usually will) end up with a
2nd ptNum, epiNum for each patient/episode. *While I can program
around this in the application I was wondering if I could do this
in MySQL so that I ended up with just one ptNum, epiNum pair.

-- Bill Drescher william {at} TechServSys {dot} com

A UNION is DISTINCT by default. You have to code UNION ALL to stop it
being DISTINCT.
Gee, that was easy !:-)
Thanks.
bill

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.