Using DECODE Statement in SQL [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I have been trying to learn SQL, and I was learning the DECODE statement:
This is the query I was trying to use:
SELECT DECODE(FIRST_NAME,'Steven','Name is Steven','Neena','Name is Neena','Some other name') AS "NAME" FROM hr.employees;
This query works successfully,but when I try the query:
SELECT DECODE(FIRST_NAME,'Steven','Name is Steven','Neena','Name is Neena','Some other name') AS "NAME" WHERE FIRST_NAME='Steven' FROM hr.employees;
This query gives me the output as:
ORA-00923: FROM keyword not found where expected
Can anyone explain me what's wrong?

Where clause needs to be placed after From clause.
SELECT DECODE(FIRST_NAME,'Steven','Name is Steven','Neena','Name is Neena','Some other name') AS "NAME"
FROM hr.employees
WHERE FIRST_NAME='Steven';

Related

Filter a column on Oracle SQL developer like '%+%' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I want to display all the names in a table that contains the character '+' but it doesn't work on Oracle SQL developer, while the column contains names with '+'
Select *
from Table where NAME like '%+%';
==> I got an empty output
Example:
Could you help me please ?!
You can use this statement:
Select *
from Table where NAME like '%' || chr(43) || '%';
Thank you

I'd like to insert any value using 'insert into' but it doesn't work. What is "Column not found error"? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I created table "member". It has two columns name, id and no values. And I'm trying to insert value "spring" into column name!
But It doesn't work...Can anybody help me please?
I wrote like this:
insert into member(name) values("spring");
error is:
Column "spring" not found; SQL statement:
insert into member(name)
values("spring") [42122-200] 42S22/42122
You should use single quotes for your String/Varchar values.
Try this query:
insert into member(name) values('spring');

Postgres Error : syntax error at or near "(" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am getting this error
ERROR: syntax error at or near "("Position: 65```
for the following query
insert into Employee(no,name,phone) values ((1,Kenit,999999999)(2,Kenit,999999999)(3,Kenit,999999999)(4,Kenit,999999999)(5,Kenit,999999999)(6,Kenit,999999999))
Probably you need commas between paranthesis for each record. And "Kenit" should be in quotes
insert into Employee(no,name,phone) values ((1,'Kenit',999999999),
(2,'Kenit',999999999),(3,'Kenit',999999999),(4,'Kenit',999999999),
(5,'Kenit',999999999),(6,'Kenit',999999999))
Try googling.
Source: https://www.sqlservertutorial.net/sql-server-basics/sql-server-insert-multiple-rows/
INSERT INTO table_name (column_list)
VALUES
(value_list_1),
(value_list_2),
...
(value_list_n);
INSERT INTO Employee (no,name,phone) VALUES ((1,Kenit,999999999),(2,Kenit,999999999),(3,Kenit,999999999),(4,Kenit,999999999),(5,Kenit,999999999),(6,Kenit,999999999));
happy to help
also: phone numbers should be saved in strings, as well as your names. so adding quotation marks helps not only in readability of the code it gives required LOGIC:
example:
...('asdf', 123, '+8920841209')

How to get exact result from charindex? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
select *
from table_name
where charindex(dest_mail,'abc#mail.com') >0
In the above query dest_mail is a column, but there is another entry in the table, which is 'bc#mail.com'. When I try to execute the above query, I'm getting two results
1.abc#mail.com
2.bc#mail.com
How to get exact 'abc#mail.com'?
Have you considered =?
where dest_mail = 'abc#mail.com'
Also, charindex() is not very colloquial SQL for this purpose; = is a built-in standard operator (charindex() is not standard). And a bonus to = is that it allows the optimizer to take advantage of indexes and partitions.

SQL COUNT() statement not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to return the total number of reserved seats in my flightbooking table using a flightID number.
SELECT COUNT(flight.flightid) AS reservedseats FROM flightbooking
WHERE status=R
I get an error saying
ERROR: missing FROM-clause entry for table "flight"
LINE 1: SELECT COUNT(flight.flightid) AS reservedseats FROM flightbo...
What am i doing wrong?
Try:
SELECT COUNT(flight.flightid) AS reservedseats
FROM flightbooking AS flight
WHERE status='R'
You were referring to flight.flightid but there isn't a table with name or alias flight. The engine doesn't know where it should retrieve flightid from.
You were also missing quotes around the char value R.
In your comment you say "I know nothing about SQL". It is much appriciated if you do some research yourself before you come here asking for help.