Search code examples
mysqlsqlinner-join

Error Code: 1066. Not unique table/alias: 'ordertbl' - Not able to Perform Inner Join MYSQL


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';

Solution

  • 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';