-1

Hi I am trying to List the order number, order date, customer number, and name (first and last) of orders placed in January 2030 by Colorado customers (CustState) but sent to Washington recipients (OrdState).Using INNER JOIN style and the columns are from 2 different tables - Customer and Orders, with the primary key as CustNo

select OrdNo, OrdDate, CustNo, CustFirstName, CustLastName from ordertbl, customer
inner join customer on CustNo = CustNo
WHERE ordDate like '%2030-01%' AND custstate ='CO' AND OrdState ='WA';
Ruth Ineh
  • 43
  • 1
  • 10
  • 1
    Learn about table aliases & needing them to self-join. This is a faq. Before considering posting please always google any error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names & site:stackoverflow.com & tags, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. – philipxy Jan 31 '20 at 06:39
  • Please in code questions give a [mre]--cut & paste & runnable code; example input (as initialization code) with desired & actual output (including verbatim error messages); tags & versions; clear specification & explanation. For errors that includes the least code you can give that is code that you show is OK extended by code that you show is not OK. (Debugging fundamental.) [ask] For SQL that includes DBMS & DDL, which includes constraints & indexes & tabular initialization. – philipxy Jan 31 '20 at 06:39
  • Does this answer your question? [Why does this SQL code give error 1066 (Not unique table/alias: 'user')?](https://stackoverflow.com/questions/1435177/why-does-this-sql-code-give-error-1066-not-unique-table-alias-user) – philipxy Jan 31 '20 at 06:47
  • @RuthIneh . . . Why are you using string functions on a date column? That looks wrong. – Gordon Linoff Jan 31 '20 at 10:56

1 Answers1

2

I think your inner join syntax is incorrect. Please try below-

select
     o.OrdNo, o.OrdDate, c.CustNo, c.CustFirstName, c.CustLastName 
from ordertbl as o
inner join customer as c on c.CustNo = o.CustNo
WHERE o.ordDate like '%2030-01%' 
      AND c.custstate ='CO' 
      AND o.OrdState ='WA';
DatabaseCoder
  • 2,004
  • 2
  • 12
  • 22