I have table with id, Advert_ID and iso_code (screen). I need to return ID for example like on screen I have Advert_ID = 22 with ID 1 and 2 with iso_code = en_US and de_DE but if Advert_ID have iso_code = en_US return only id = 1 if not return all ID ( Advert_ID = 11 doesn't has iso_code = en_US so return Id 3 and 4)
From your comment :
I need to select all "Advarte_ID" and check iso_code if = 'en_US" return only ID with 'en_US' .
If I understand you verry well, that will help :
SELECT ID FROM YourTablName WHERE iso_code = 'en_US';
That will return only
Advert_IDs which have `iso_code = 'en_US'.
IF EXISTS (SELECT * FROM YourTable WHERE WHERE iso_code = 'en_US') BEGIN SELECT ID FROM YourTablName WHERE iso_code = 'en_US'; END ELSE BEGIN SELECT ID FROM YourTable; END