How to do join using select [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 2 days ago.
This post was edited and submitted for review 2 days ago.
Improve this question
SQL Newbie here ...
Service_plan table has a record per customer with PKEY service_plan_id
SERVICE_PLAN_ID table keeps track of version changes with same PKEY
When I run this query [other selects omitted for brevity] in Oracle 10.2.0 iSQL command line, I get an error:
select S1.service_plan_id as TN,V1.VERSION_ID as Version
from Service_plan S1
inner join
(select distinct service_plan_id, max(VERSION_ID)
from SERVICE_PLAN_VERSION
where service_ID='COLL'
group by service_plan_id) as V1
on V1.SERVICE_PLAN_ID = S1.SERVICE_PLAN_ID
where S1.SERVICE_ID='COLL';
Error: missing key word on the "group by service_plan_id) as V1" line - it points to the "as" as the problem.
Any thoughts? Thx
Tried the standalone select and it works fine

Related

Access SQL Syntax error - Unable to find the 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 9 days ago.
Improve this question
SELECT AgentData.AgentLoginID,AgentData.KPIName,Minimum.Indicator,Minimum.PMonth,Minimum.PYear,Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue,
Round(IIf([Minimum].[Indicator]='P',(IIf([Goal]=0,Null,[GoalValue]/[Goal]),IIf(([Minimum].[Indicator]='N' And ([Minimum].[Min]=0 Or [Minimum].[Min]=(format(0,"Percent")),Null,([Minimum].[Min]-[GoalValue]/[Minimum].[Min]),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
I have been trying to execute this code in access, but no success, i keep getting a syntax error, missing operator in expression, but unable to figure out what the issue is, so wondering if anyone could help, i get an error with the SQL statement marked in bold
SELECT AgentData.AgentLoginID, AgentData.KPIName, Minimum.Indicator, Minimum.PMonth, Minimum.PYear, Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue, Round(IIf([Minimum].[Indicator]='P',IIf([Goal]=0,Null,[GoalValue]/[Goal]),
IIf(([Minimum].[Indicator]='N' And [Minimum].[Min]=0),Null,([Minimum].[Min]-[GoalValue])/[Minimum].[Min])),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product
FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
The above query runs perfectly fine, but i get a snytax errors when i add the OR operator for Minimum.Min as i want it to exectue in two scenarios , one is when Minmum.min is 0 or when minimum.min = 0%

Postgresql missing FROM-entry for table [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 years ago.
Improve this question
I have 2 tables
messages
respondents
and I'm trying to join them using a simple inner join query
SELECT
Message.content,
Message.created_at,
Respondent.name
FROM
MESSAGES
INNER JOIN RESPONDENTS ON Message.respondent_id = Respondent.id;
and I'm getting this error:
ERROR: missing FROM-clause entry for table "message"
LINE 1: ...dent.name FROM MESSAGES INNER JOIN RESPONDENTS ON Message.re...
Can anyone help me out??
There are two typos in your query. Try this - assuming your tables are called respondents and messages:
SELECT
messages.content, messages.created_at, respondents.name
FROM messages
INNER JOIN respondents ON messages.respondent_id = respondents.id;

Wrongly closed SQL parentheses [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'm fairly new at writing SQL commands so I don't exactly know where I'm going wrong here. I closed all the parentheses, but I still get the following error message:
Syntax error: Expected ")" but got keyword AND at [18:5]
Code:
goals as (
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals
goal_total
and extract(month from [daterange_start]) = month
)
Any hints?
WHERE Clause is missing :
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals as goal_total
where extract(month from [daterange_start]) = month

Select * From Table Where column=data is 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 3 years ago.
Improve this question
I am using SQL Server. The following query is working fine:
select *
from Users
where Users.Id = 1
but when I use
select *
from Users
where Users.Username = "User"
this does not work.
Error:
Invalid Column name
Use on quote instead of double quote
select * from Users where Users.Username = 'User'
text datatype has been deprecated, you need to change the datatype to VARCHAR(n)/NVARCHAR(n) as it depends on your data and your needs.

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.