I have a query where I am testing an ‘IN’ against a select.
I am getting an “Operand should contain 1 column(s)” error which I assume is because I am selecting more than 1 column in my ‘IN’ Select. I need the second column as part of my selector because I need to check it against a ‘having’ statement.
How can I make this work to get my desired effect?
SELECT DISTINCT c.ID, Title, URLSegment
FROM ListingCategory c
LEFT JOIN SiteTree_Live ON c.ID = SiteTree_Live.ID
JOIN ListingCategory_Listings lc
ON c.ID = lc.ListingCategoryID
WHERE lc.ListingID IN (
SELECT Listing.ID,
( 6371 * ACOS( COS( RADIANS(-45.0227996) ) * COS( RADIANS( Location.Latitude ) ) * COS( RADIANS( Location.Longitude ) - RADIANS(168.6991149) ) + SIN( RADIANS(-45.0227996) ) * SIN( RADIANS( Location.Latitude ) ) ) ) AS distance
FROM Listing
LEFT JOIN Location ON Listing.LocationID = Location.ID
having distance < 5
);
Easy – just don’t select the calculated column. Also, it should be
WHERE, notHAVING: