0

I have the following tables and I have to get all orders of customer Meier.

Table Customer with columns cid and name:

cid           name
-------------------------
13            M. Mueller
17            A. Meier
23            I. Schulze

Table Orders with columns Oid, Did, Date and Cid:

Oid       Did       Date          Cid
--------------------------------------
3         7        2002-12-01     17
5         11       2003-04-27     23
7         5        2003-05-13     17
10        5        2003-09-01     13

What I have tried is the following:

SELECT Oid.Orders, Did.Orders, Date.Orders, Cid.Orders,
FROM Orders
INNER JOIN Customer ON Cid.Orders = cid.Customer
WHERE name.Customer = "A. Meier"

But there is a syntax error that I am not able to find. How should I proceed in this case?

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Maria
  • 47
  • 1
  • 7
  • 3
    Double quotes are for delimited identifiers, e.g. strange column names. Use single quotes for string literals. – jarlh Jun 15 '20 at 08:37
  • 1
    Basic debugging says, chop away code until you don't get an error, add back, repeat until you can't remove any more. Put expressions on separate lines to get more specific error messagee. This is a faq, google your error without you particular strings. In coce questions give a [mre]. But this will be a faq when you pin it down. – philipxy Jun 15 '20 at 08:41

2 Answers2

0

Where customer.name ... should do the trick. You have several similar errors in your query with field.table instead of table.field

iDevlop
  • 24,841
  • 11
  • 90
  • 149
0

The best way is to use aliases. So your select statement should look like this(I will use alias o for Orders and c for Customer):

 SELECT * from Orders o inner join Customer c on c.cid=o.Cid where c.name='A. 
 Meier'

If you would like to solve the problem without aliases (which I don't prefer), you should do this:

 SELECT Orders.Oid, Orders.Did, Orders.Date, Orders.Cid,
 FROM Orders
 inner JOIN Customer ON Orders.Cid = Customer.cid
 where Customer.name = 'A. Meier'

So table name before table attribute. And be careful around the quotes... " and ' have different meaning... It also leads in errors. Please read this post What is the difference between single and double quotes in SQL?

XraySensei
  • 167
  • 7
  • Please don't just post code, explain why it is an answer. [answer] [help] – philipxy Jun 15 '20 at 08:39
  • Please format code reasonably. In other words, please think about what you are doing & make a clear well presented permanent communication. Which you should know without someone telling you. – philipxy Jun 15 '20 at 08:43