Reputation: 21
List authors who have 'e' as the 4th letter in first name or last name, and have a pseudonym.
select * from authors
where last_name like '___e%' or first_name like '___e%' and pseudonym is not null and pseudonym <> ' ';
The output still show the row where pseudonym are null (picture)
Upvotes: 0
Views: 2874
Reputation: 1612
select *
from authors
where (last_name like '___e%' or first_name like '___e%') and
trim(pseudonym) is not null;
Upvotes: 2
Reputation: 1269693
You need parentheses:
select *
from authors
where (last_name like '___e%' or first_name like '___e%') and
pseudonym is not null and
pseudonym <> ' ';
If you are learning SQL, then use parentheses whenever your conditions have more than one logical operator (such as (AND
) and (OR
)).
The comparison is not null
is redundant. I would recommend that you leave it in anyway, just to be explicit about the conditions.
Upvotes: 1