Reputation: 15925
I have the table:
ID, firstname, lastname, companyName, isCompany
How do I run a query such that I can do:
SELECT ID, name FROM myTable ...
where the name is an algorithm along the lines of
if(isCompany)
name = companyName
else
name = "lastname, firstname"
Upvotes: 0
Views: 107
Reputation:
You didn't state your DBMS but this is ANSI SQL:
select id,
case
when is_company then companyName
else lastname||', '||firstname
end as name
from my_table
This assumes that is_company
is of type boolean
Upvotes: 2