SQL COUNT() statement not working [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 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.

Related

It seems like my min/max functions for my SQL code are reversed [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 2 days ago.
Improve this question
I'm using Microsoft SQL Server and I"m having issues writing a command for MIN and MAX functions.
It seems simple. The data type of the column is date time and the requested information is to find oldest/newest employee.
Below is the query I wrote:
select max(date_hired)
from staff;
select min(date_hired)
from staff;
But it seems like they are working in reverse. Min is giving me oldest and max is giving me youngest.

Using DECODE Statement in SQL [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 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';

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 column doesn't exist error on update [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
I am trying to run the query below but I am getting an error ERROR: column "test.pdf" does not exist . I dont know why I am getting this error. I search for various links on stackover but none solved my problem like this PostgreSQL query -- column does not exist, Postgres error updating column data. Please help me find the problem.
bill is a type string field in bills table.
update bills
set bill = "test.pdf"
where id=3;
Change the double quotes you have around test.pdf to single quotes.

ORA-00918 Column ambiguously defined [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
SELECT INDIVIDUAL.INV_FNAME,
INDIVIDUAL.INV_LNAME,
INDIVIDUAL.INV_IC_NUM,
CUSTOMER.MEMBER_LEVEL,
CUSTOMER.MEMBER_POINT_BALANCE,
CUSTOMER.MEMBER_DISCOUNT_RATE,
PROGRAM_USER.USER_CONTACT_NUM,
PROGRAM_USER.USER_ADDRESS,
PROGRAM_USER.USER_CITY,
PROGRAM_USER.USER_STATE,
PROGRAM_USER.USER_ZIP_CODE,
PROGRAM_USER.USER_COUNTRY,
PROGRAM_USER.USER_EMAIL
FROM PROGRAM_USER,CUSTOMER,INDIVIDUAL
WHERE USER_ID = ‘san’;
In your query only USER_ID column in the where condition is not specified with a table name. I guess USER_ID is there in multiple table. Try the where condition with proper table name
SELECT INDIVIDUAL.INV_FNAME,
INDIVIDUAL.INV_LNAME,
INDIVIDUAL.INV_IC_NUM,
CUSTOMER.MEMBER_LEVEL,
CUSTOMER.MEMBER_POINT_BALANCE,
CUSTOMER.MEMBER_DISCOUNT_RATE,
PROGRAM_USER.USER_CONTACT_NUM,
PROGRAM_USER.USER_ADDRESS,
PROGRAM_USER.USER_CITY,
PROGRAM_USER.USER_STATE,
PROGRAM_USER.USER_ZIP_CODE,
PROGRAM_USER.USER_COUNTRY,
PROGRAM_USER.USER_EMAIL
FROM PROGRAM_USER,CUSTOMER,INDIVIDUAL
WHERE PROGRAM_USER.USER_ID = ‘san’;
Also like #HoneyBadger comment you need to specify the join between the tables