I am trying to select the data where the gender is female or x. It can not be male the code I am using returns Missing Expression :
SELECT pet_id, name, gender, type, breed
FROM Pet
WHERE Name Like '%s' or Name like 'S%'
And WHERE Gender ='F' or Gender ='X';
Is my formatting okay?
In your query you have used the where
keyword twice which is not valid.
The sql syntax prohibits you from doing so, you can have one from
and where
per select
keyword.
to select multiple fields, you separate by commas.
to select from multiple tables, you separate by commas.
to use multiple conditions in your where clause you use and
& or
(this rule applies to most programming languages, you cannot have for example if(x1==1 and if (x2==2))
instead you use if(x1==1 && x2==2)
)
also try using the in
operator for your condition on gender, as such
Gender in('F','X')
the in operator allows you to check if the value of a given column exists in an array/list/series of possible values.
You have duplicated "where" in your query. Rewrite in following way should work:
SELECT pet_id, name, gender, type, breed
FROM Pet
WHERE (Name Like '%s' or Name like 'S%') AND (Gender ='F' or Gender ='X');
Try this
SELECT pet_id,name,gender,type,breed FROM Pet
Where (Name Like '%s' or Name like 'S%')
And (Gender ='F' or Gender ='X');
We can't use 'Where' multiple times in single query and as i see in your case you should apply round brackets.
Remove second WHERE and don't forget brackets:
SELECT pet_id, name, gender, type, breed
FROM Pet
WHERE (Name Like '%s' or Name like 'S%')
And Gender in ('F','X')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.