0
Please , can someone point out my mistake ? It's an SQL task.
I'm working on an SQL task which asks me to sort cars by model year. My code : SELECT company, year FROM cars ORDER BY company WHERE year = 2020; When i run it , the app says this : "ERRO: syntax error at or near "WHERE" LINE 4: WHERE year = 2020; ^ " Any ideas ? As always , i greatly appreciate this community ! :).
14 Réponses
+ 11
Try to place filter specification first (WHERE), then followed by sorting specification (ORDER BY).
SELECT company, year
FROM cars
WHERE year = 2020
ORDER BY company;
+ 6
Well, that's odd, let's see what others has to say ...
Did the task specify to filter cars built around 2020? (WHERE year = 2020)? maybe it can be removed.
BTW, your Description said "to sort cars by model year" I think the ORDER BY should use 'year' rather than 'company'.
+ 3
Well, I don't know either.
But if that solves the case then it's good news! 👍
+ 2
Apparently the Description in the original post above was different with the most recent one you shared.
I'm sorry my suggestion didn't work out, but I'm pretty sure someone more knowledgeable can assist you to get through 👍
+ 2
Ipang
Indeed ! :).
+ 1
Ipang
Thank you for the suggestion , but the only thing that changed is that the ERROR message now says the same thing , but with ORDER BY instead pf WHERE.
+ 1
@Ipang
This is the description :
The WHERE Statement
"You are given the following table of cars with details
:contentImage
Write a query to output the brand and model years of the cars produced in 2020, sorted by the 'company' column.
Use the WHERE statement!"
I've used your suggestion of changing the ORDER BY , but it only changed the ERROR message to the first one i got. Thank you for this suggestion nonetheless ! :).
+ 1
Ipang
Oh , sorry. Thank you for your time & have a great day with fantastic luck , wherever & whenever you are ! :). 👍
+ 1
Ipang
Hey , Ipang ! After some Googling , i found this code from one
@Såñtösh
Here it is :
select company ,year from cars where year=2020 order by company;
I don't know how , but it worked.
+ 1
try this and it will resolve the problem. thanks for understanding
select company, year
from cars
where year=2020
order by company Asc;
0
To type the order by is after where condition
0
FREDERIC DANIMBE
Hi , Frederic ! I have solved this issue long ago , but thank you for your help nonetheless ! Have a great day & fantastic luck ! :).
0
U should put 'order by' after 'where' condition
0
select * from cars where engine ='electric' or year > 2018