Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to exclude duplicates from Select with UNION?
Message
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
How to exclude duplicates from Select with UNION?
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01108675
Message ID:
01108675
Views:
50
Hi everybody,

Here is my code to get queues by role
local lcSQLStr, lcFilter1, lcFilter2

lcFilter1 = [Employee_Queue_Profiles.cUsGrLink_fk = '] + crsUsGrLink.cUsGrLink_pk + [']
lcFilter2 = [Queue_Names.cDepartment_Code = '] + ;
	strtran(left(cDepartments.cDepartment_Code,1),'C','O') + [']

text TO lcSQLStr TEXTMERGE noshow
   SELECT 1 as iSelected, ;
   Employee_Queue_Profiles.iDefault_queue_flag as iDefault_Queue_Flag, ;
   Queue_Names.cQueue_names_pk, Queue_Names.cQueue_name, ;
   Queue_Names.cDepartment_code, Queue_Names.cQueue_type_code, Queue_Names.cQueue_type_id ;
   FROM Employee_Queue_profiles INNER JOIN Queue_Names ;
   ON Employee_Queue_Profiles.cQueue_Names_fk = Queue_Names.cQueue_Names_pk ;
   WHERE Employee_Queue_Profiles.iActive_Flag = 1 AND <<m.lcFilter1>> ;
   UNION ;
   select 0 as iSelected, 0 as iDefault_Queue_flag, ;
    Queue_Names.cQueue_names_pk, Queue_Names.cQueue_name, ;
   Queue_Names.cDepartment_code, Queue_Names.cQueue_type_code, Queue_Names.cQueue_type_id ;
   FROM Queue_Names WHERE Queue_Names.cQueue_Name NOT LIKE 'UNASSIGNED%' AND <<m.lcFilter2>> ;
   ORDER BY 4
ENDTEXT

if RunSQL(m.lcSQLStr, 'curTempQueues')
	zap in cQueueNames
	insert into cQueueNames select * from curTempQueues
	GO TOP IN cQueueNames
	use in curTempQueues
endif
If I have queues in Employee_Queue_Profile, I don't want them listed twice. However, currently they are listed twice, I believe, because of extra fields. Is my only option to do this in two separate select statements?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform