Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: IN statment

$
0
0

ok.  wow.  interesting table design for this purpose.  Here is what you are going to have to do, more or less (ie, I have not done this in SSMS for you, so it might need some fine tuning):

 

SELECT COUNT(*) as TOT,id from

(

     select ACCOUNT_bus_id, Account_bus_name,Account_bus_amid AS ID

     FROM activities_bus_tb

UNION ALL

    

select ACCOUNT_bus_id, Account_bus_name,Account_bus_busid AS ID

     FROM activities_bus_tb

)

HAVING COUNT(*) > 1

GROUP BY ID

ORDER BY ID

 

this should give you the list of IDs that are in multiple records.  You can then feed that list into the orginial query's IN statement to pull out the rest of the data related to those IDs that appear in 2 places.

 

The problem with the table design is that you have two columns that hold the same object (the ID value).  Normalizing the table so that there is just one ID column instead of two, and then having another table that contains the IDs and also some indication as to whether it is a AMID or a BUSID would make it possible to do this in a simpler query.

 

good luck!

-reed


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>