'SQL WHERE/AND error when using it multiple times
I've started learning SQL on Friday. I'm using pgAdmin4
I'm having trouble with one line on this code:
SELECT first_name, last_name, nationality, date_of_birth
FROM DIRECTORS
WHERE nationality IN ('French' , 'German', 'British');
AND date_of_birth BETWEEN 01/01/1940 AND 31/12/1969; // error
The first 3 lines work, they list everything as needed, the 4th line is giving me an error
ERROR: syntax error at or near "AND" LINE 4: AND date_of_birth BETWEEN 01/01/1940 AND 31/12/1969;
On the fourth line I'm trying to check date_of_birth between =>01/01/1940 && <=31/12/1969.
I still get an error when I use WHERE
instead of AND
on the 4th line, I don't know what word to use (AND,WHERE,etc) when I am being asked to find more details in a database.
Any help appreciated.
Solution 1:[1]
Enclose your date in a single quote
or double qoute
. And use a proper date format 'yyyy-MM-dd'
and remove the first ;
.
SELECT first_name, last_name, nationality, date_of_birth
FROM DIRECTORS
WHERE nationality IN ('French' , 'German', 'British')
AND date_of_birth BETWEEN '1940-01-01' AND '1969-12-31';
Solution 2:[2]
the time style that mysql supports is yyyy-MM-dd( HH:mm:ss) AND date_of_birth BETWEEN '1940-01-01' AND '1969-12-31';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kuro Neko |
Solution 2 | fucius |