SQL: Avoiding Union queries
Posted on 2014-04-24
I'm trying to find ideas for doing a query in a different, more efficient manner.
I have a Query like:
Select [Fields], [aField]
where [aField] in ( 2034, 3345, 5678, 2323)
and [other where stuff]
Works great. Gives me a separate row for every number for [aField]
The problem is that each of the numbers also have a VarChar category attached to them. For example, 2034 is a FORD, 3345 and 2323 is a VW, 5678 is a Saturn, etc.
So on the individual row, instead of the numbers I need the VarChar. In some cases, there is more than one number attributable to the same VarChar and I need to have only one row for those VarChars.
I could do a query for each Varchar and UNION them, however, it seems there should be an easier way to accomplish this.