Skip to content
Advertisement

Select horses with logical operators [closed]

I dont know where i am messing up at but im currently learning SQL and this has been frustrating me a bit.

The Horse table has the following columns:

ID - integer, primary key
RegisteredName - variable-length string
Breed - variable-length string
Height - decimal number
BirthDate - date

Write a SELECT statement to select the registered name, height, and birth date for only horses that have a height between 15.0 and 16.0 (inclusive) or have a birth date on or after January 1, 2020.

This is what ive written

SELECT *
FROM Horse
WHERE (Height >= '15.0' AND <= '16.0') 
   OR BirthDate >= '2020-01-01';

This is the Error It Keeps Giving me Query failed: ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘<= ‘16.0’) OR BirthDate >= ‘2020-01-01” at line 3

Advertisement

Answer

Maybe try this

SELECT *
FROM Horse
WHERE (Height >= '15.0' AND Height <= '16.0') 
   OR BirthDate >= '2020-01-01';
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement