Need to select the one value if it exists otherwise another value
Need to select the one value if it exists otherwise another value
(OP)
I'm not sure how to go about this. In my tbl_Project_Employee below I have 4 dummy records. I need a query that selects where the employee_type_id = 48 if it exists; otherwise I select where the employee_type_id = 22. I've shown below the table what my results should be.
Thanks,
Sherry
CODE --> sql
tbl_Project_Employee ProjectID Employee_Type_ID Employee_Type_Desc Email 001 48 Public_Contact john.doe@anywhere.com 001 22 Project_Manager jane.doe@anywhere.com 002 48 Public_Contact susan.jones@anywhere.com 003 22 Project_Manager david.howard@anywhere.com Results S/B: ProjectID Employee_Type_ID Employee_Type_Desc Email 001 48 Public_Contact john.doe@anywhere.com 002 48 Public_Contact susan.jones@anywhere.com 003 22 Project_Manager david.howard@anywhere.com
Thanks,
Sherry
RE: Need to select the one value if it exists otherwise another value
CASE
WHEN select * from tbl_Project_Employee where Employee_Type_ID = '48' IS NULL
THEN select * from tbl_Project_Employee where Employee_Type_ID = '22'
ELSE select * from tbl_Project_Employee where Employee_Type_ID = '48'
END
There is a better way to do this, and someone will post it. But this works and you should learn the CASE syntax.
==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity
RE: Need to select the one value if it exists otherwise another value
RE: Need to select the one value if it exists otherwise another value
CODE
Of course, this is answering your original question. Looking at the solution you came up with, I think it would definitely be more efficient since you would not have to be doing outer joins on twin sets of tables. The resultant query would take a general form of
CODE
RE: Need to select the one value if it exists otherwise another value