Missing keyword - inner join with where - oracle

post_code is a primary key in the location table and foreign key in job. I am trying to join them, could anyone help.
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location job.post_code ON location.post_code AND country_name_location = 'France';
SQL Error: ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:

Your ON is in the wrong position:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';

There is an error in your syntax. The ON keyword is meant to come after you specify the table you are joining with. So the correct query would be:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';

Related

Correct syntax for table name under Inner Join?

I am a complete beginner to BigQuery, and I am trying to create an inner join between two table names, where the column 'title' is the joining column. I believe my syntax is correct, but I do not know what I am doing wrong when I input the ON clause. Here is my syntax:
SELECT
*
FROM
book-to-film-adaptations.movies.movies_metadata_relevant
JOIN
book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data
ON
movies_metadata_relevant.title = goodreads_books_relevant_data.title
I get this error message: Unrecognized name: movies_metadata_relevant at [8:3]
I have tried it with the full names (book-to-film-adaptations.movies.movies_metadata_relevant), but then I get an error message: "Syntax error: Unexpected keyword TO"
Any suggestions?
Thanks
You need to alias tables and use those like in below example - but in this case you will need
...
...
FROM
`book-to-film-adaptations.movies.movies_metadata_relevant` t1
JOIN
`book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data` t2
ON
t1.title = t2.title
or if join columns have same name (like in your case) you can use below version
...
...
FROM
`book-to-film-adaptations.movies.movies_metadata_relevant` t1
JOIN
`book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data` t2
USING (title)

INNER JOIN two table get error SQL Statment not ended properly

I have two table which I want to select Name from t2.
The situation is following.
I have t1 Policy which containt EmployeeID
And table t2 which containt Name
Now I want to select which Employee release policy.
So in t1(Policy- AUTO.POL) I have column: SIFRA_RAD
and t2(Employee-AUTO.SIFRAD) I have colum: SIFRA_R, Ime
I try something like this:
select auto.pol.sifra_rad, auto.sifrad.ime
from auto.sifrad
inner join auto.pol on auto.sifrad.ime = auto.pol.sifra_rad;
After that I get error
ORA-00933: SQL command not properly ended
I have no idea what is wrong here. Any suggestion?
The problem comes from query, and we fix it
select p.sifra_rad, s.ime from auto.sifrad s, auto.pol p where s.ime = p.sifra_rad

Query create table as with inner join select and group by (ORACLE)

This is my query, if i run the error is : Error in query: ORA-00907: missing right parenthesis, anybody can solve my problem?
Create table r_tcash_loci_act_tmp AS (
SELECT DISTINCT
R_TCASH_LOCI_ACT.MSISDN AS MSISDN_LOCI,
R_TCASH_ACT_MSISDN.MSISDN AS MSISDN_ACT,
R_TCASH_LOCI_ACT.AREA,
R_TCASH_LOCI_ACT.REGIONAL,
R_TCASH_LOCI_ACT.BRANCH,
R_TCASH_LOCI_ACT.SUB_BRANCH,
R_TCASH_LOCI_ACT.CLUSTERX,
R_TCASH_LOCI_ACT.UPDATED,
R_TCASH_ACT_MSISDN.DAILY,
R_TCASH_ACT_MSISDN.TOTAL_TRX,
R_TCASH_ACT_MSISDN.TOTAL_VOL
FROM R_TCASH_ACT_MSISDN
INNER JOIN R_TCASH_LOCI_ACT
ON R_TCASH_LOCI_ACT.MSISDN = R_TCASH_ACT_MSISDN.MSISDN
GROUP BY R_TCASH_LOCI_ACT.MSISDN AS MSISDN_LOCI
HAVING COUNT(R_TCASH_LOCI_ACT.MSISDN ) > 10);
It's a simple syntax error. You included the column alias in the GROUP BYclause (probably a cut'n'paste error).
GROUP BY R_TCASH_LOCI_ACT.MSISDN AS MSISDN_LOCI
So just remove the AS MSISDN_LOCI.
Although given that you have a DISTINCT clause and no aggregated columns it's a mystery why you have the GROUP BY at all. You should remove the whole line.

Error in semantic exception return 0 rows in hive

I got the below error in hive while I am executing the hql like this.
Select a.col,b.col from tab a left join tab b on a.id =b.id and a.code in
(Select c.code from tab c where c.id=123 and c.dec='123a');
Note: c.id is pk and c.dec is unique id
Error: semantic in exception 0 children returned.
Can any one help to resolve the above issue.
I think this is happening because you are using a MySQL reserved keyword "desc" as your column name. So you can change it and try again.
You can refer to this link for the list of all the reserved keywords for MySQL :https://dev.mysql.com/doc/refman/5.5/en/keywords.html

SQL Error: ORA-00907: missing right parenthesis in Oracle 10g

Please find the below query. When I run this query I am getting an ORA-00907: missing right parenthesis error. I am unable to understand the problem on this query. Please give me the solution for this error. I have read some related topics on this topic. but, I didn't get the right solution. I am using Oracle 10g version.
The query:
SELECT A.City||'.' AS AAddress,
M_InOut_Header_v.Org_Location_ID AS Org_Location_ID,
M_InOut_Header_v.ContactName,
M_InOut_Header_v.Title,
M_InOut_Header_v.EMail,
M_InOut_Header_v.Phone,
M_InOut_Header_v.BPGreeting,
M_InOut_Header_v.Name2,
M_InOut_Header_v.Name,
B.City||'.' AS BAddress,
M_InOut_Header_v.C_Location_ID AS C_Location_ID,
M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.BPGreeting,
--M_InOut_Header_v.Name,
--M_InOut_Header_v.Name2,
M_InOut_Header_v.Address1,
M_InOut_Header_v.Address2,
M_InOut_Header_v.Address3,
M_InOut_Header_v.Address4,
M_InOut_Header_v.City,
M_InOut_Header_v.POSTAL1,
M_InOut_Header_v.CountryName,
--M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.Name,
M_InOut_Header_v.OrderRemarks,
(SELECT NVL(C_Order.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(C_Order.DateOrdered,'DD/MM/YYYY')),'')
FROM C_Order
WHERE M_InOut_Header_v.C_Order_ID=C_Order.C_Order_ID
) AS CC_Order_ID,
M_InOut_Header_v.C_Order_ID AS C_Order_ID,
M_InOut_Header_v.OrderType,
M_InOut_Header_v.ReferenceNo,
M_InOut_Header_v.POReference,
(SELECT NVL(M_Warehouse.Name,'')
FROM M_Warehouse
WHERE M_InOut_Header_v.M_Warehouse_ID=M_Warehouse.M_Warehouse_ID
) AS DM_Warehouse_ID,
M_InOut_Header_v.M_Warehouse_ID AS M_Warehouse_ID,
(SELECT NVL(M_Shipper.Name,'')
FROM M_Shipper
WHERE M_InOut_Header_v.M_Shipper_ID=M_Shipper.M_Shipper_ID
) AS EM_Shipper_ID,
M_InOut_Header_v.M_Shipper_ID AS M_Shipper_ID,
M_InOut_Header_v.Vehicle_No_BizInt,
M_InOut_Header_v.TrackingNo,
M_InOut_Header_v.Permit_No_BizInt,
M_InOut_Header_v.LR_Number_BizInt,
M_InOut_Header_v.FREIGHTCOSTRULE2,
M_InOut_Header_v.FreightAmt,
M_InOut_Header_v.POREMARKS,
M_InOut_Header_v.NoPackages,
M_InOut_Header_v.Gross_Weight_BizInt,
M_InOut_Header_v.UOMSymbol,
M_InOut_Header_v.SalesRepPhone,
M_InOut_Header_v.SalesRepEmail,
M_InOut_Header_v.DocumentType,
InOut_Header_v.DocumentNo,
M_InOut_Header_v.MovementDate,
M_InOut_Header_v.Description,
(SELECT NVL(M_InOut.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(M_InOut.MovementDate,'DD/MM/YYYY')),'')
FROM M_InOut
WHERE M_InOut_Header_v.M_InOut_ID=M_InOut.M_InOut_ID
) AS FM_InOut_ID,
M_InOut_Header_v.M_InOut_ID AS M_InOut_ID,
M_InOut_Header_v.DocumentTypeNote,
M_InOut_Header_v.REMARKS1,
M_InOut_Header_v.REMARKS2,
M_InOut_Header_v.REMARKS3,
M_InOut_Header_v.REMARKS4
FROM M_InOut_Header_v
LEFT OUTER JOIN C_Location A
ON (M_InOut_Header_v.Org_Location_ID=A.C_Location_ID)
LEFT OUTER JOIN C_Location B
ON (M_InOut_Header_v.C_Location_ID=B.C_Location_ID)
WHERE (M_InOut_Header_v.M_InOut_ID=1002241)
AND M_InOut_Header_v.AD_Client_ID IN (1000008,0)
AND M_InOut_Header_v.AD_Org_ID IN (1000099,1000098,0,1000100,1000096,1000097)
AND (A.C_Location_ID IS NULL
OR A.C_Location_ID NOT IN (
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
))
AND ( B.C_Location_ID IS NULL
OR B.C_Location_ID NOT IN (
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
))
ORDER BY M_InOut_Header_v.DocumentNo;
This gives me:
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 80 Column: 26
But I didn't find any mistake in that line. I think it is syntactically correct.
The line number is slightly misleading, but it's pointing to the start of the problem. The issue is with these two subqueries:
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
and:
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
You cannot use AS to mark an alias for a table name, only (optionally) for a column name or expression. There isn't actually a missing parenthesis. It's hard to know exactly what the parser is thinking, but in this case it looks like it's trying to interpret the AS PA as a column alias for that subquery, and that implies that the subquery should have ended by now, and so there should have been a close parenthesis already. (Another option might have been to try to treat AS as the table alias, but then it would have had to try to decide what PA meant; plus AS is a keyword so it wouldn't be valid as an alias name anyway).
Just remove the AS keyword from both of those and it'll work (or move on to another error).
SELECT PA.Record_ID FROM AD_Private_Access PA
...
and:
SELECT ADP.Record_ID FROM AD_Private_Access ADP
...

Resources