SO community, here's my SQL query which runs with no error:
SELECT DISTINCT
(L.LOCATION) AS "LOC",
C.CITY_NAME AS "CIT",
H.STREET_NAME AS "STR",
U.APT_NAME AS "APT",
U.NUM AS "NUM",
L.DESCRIPTION AS "DES",
H.POP AS "POP",
S.STATE_CODE AS "STA",
H.SITE_NAME AS "SIT",
U.COUNTY AS "COU",
L.DESCRIPTION AS "PRO"
FROM
LOCATIONS L
LEFT OUTER JOIN CGZIP9 Z
ON L.L_ZIPCODE = Z.ZIPCODE
LEFT OUTER JOIN STREET_V H
ON L.LOCATION = H.LOCATION
LEFT OUTER JOIN CGZIPCITY Y
ON Z.CITYID = Y.CITYID
LEFT OUTER JOIN CGCITY C
ON Y.CITYID = C.CITYID
LEFT OUTER JOIN CGSTATE S
ON C.STATEFIPS = S.STATEFIPS
LEFT OUTER JOIN UNIT U
ON L.UNITID = U.UNIT_ID
WHERE
L.LOCATION IN ('1', '2', '3', '4', '5', '1', '2', '4')
ORDER BY L.LOCATION ASC;
I'm trying to retrieve records for all values in my IN (even the duplicates such as '1', '2', & '4')
Here's my output when I run the above code:
=============================================
|LOC|CIT|STR|APT|NUM|DES|POP|STA|SIT|COU|PRO|
=============================================
| 1 | X | X | X | X | X | X | X | X | X | X |
| 2 | X | X | X | X | X | X | X | X | X | X |
| 3 | X | X | X | X | X | X | X | X | X | X |
| 4 | X | X | X | X | X | X | X | X | X | X |
| 5 | X | X | X | X | X | X | X | X | X | X |
=============================================
Here's my desired output:
=============================================
|LOC|CIT|STR|APT|NUM|DES|POP|STA|SIT|COU|PRO|
=============================================
| 1 | X | X | X | X | X | X | X | X | X | X |
| 2 | X | X | X | X | X | X | X | X | X | X |
| 3 | X | X | X | X | X | X | X | X | X | X |
| 4 | X | X | X | X | X | X | X | X | X | X |
| 5 | X | X | X | X | X | X | X | X | X | X |
| 1 | X | X | X | X | X | X | X | X | X | X |
| 2 | X | X | X | X | X | X | X | X | X | X |
| 4 | X | X | X | X | X | X | X | X | X | X |
=============================================
Any suggestions as to how I can accomplish this?
instatement has won't make any difference on what rows are returnedDISTINCT, the query should work, showing you the records in the same way you need.x in (1,1)means the same thing as(x = 1 or x = 1), so you would just get rows wherex = 1. It's like requesting "all pets that are cats or cats". You don't get all the cats twice.