Skip to content
Advertisement

SQL query base on three relation with restriction

  • Customer (CustomerID, FirstName, LastName, Email, PostCode)
  • Salesman (SalesmanNo, empName)
  • Account (AccountNo, SalesmanNo, CustomerID, AccountType)

How do I achieve this:

Get the name of customer purchase from both Sean and Jean, i believe with the below nested query statement I get the customerID who purchase from both salesman.

result like

but when i add

I get error ORA-00905: missing keyword 00905. 00000 – “missing keyword” *Cause:
*Action: and the CID is flag so when i placed my cursor the CID (Syntax Error. Partially recognized rules(railroad diagram):


Please help

Advertisement

Answer

Despite the fact that you will get similar results for JOIN and IN, it is better to use IN predicate for filtering and JOIN part to enrich the data with more data. Because over the years from IN you’ll expect nothing more than filtering and will not need to try to remember or understand the purpose of any particular JOIN.

Your error is cause by AS before table alias CID, because Oracle does not expect AS before it. The query is:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement