0

While implementing the below query:

select distinct(city) 
from station 
where substr(distinct(city),1,1) IN ['A','E','I','O','U'];

I get the following error:

ERROR at line 1: ORA-00936: missing expression

Using Oracle Sql. I am still a beginner to using SQL so just can't figure this one out

3 Answers 3

1

There is no need of writing distinct in where because you are going to get distinct value as you mention where selecting the column. And Syntax for IN

expression IN (value1, value2, ... value_n);

Corrected Query

select distinct city
from station 
where substr(city,1,1) IN ('A','E','I','O','U');
Sign up to request clarification or add additional context in comments.

1 Comment

distinct is not a function in SQL AFAIK.
0

There are two typos in your statement.

  • use classical paranthesis instead of brackets.
  • distinct clause cannot be used as an expression inside substr function (at the end results will already become distinct).

Make your sql like this :

select distinct(city) 
from station 
where substr(city,1,1) IN ('A','E','I','O','U');

Comments

0
SELECT city
FROM station 
WHERE SUBSTR(city,1,1) IN ('A','E','I','O','U')
GROUP BY city;

It's better to use GROUP BY instead of DISTINCT.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.