1

I have two tables as seen below:

ORDER enter image description here

ITEM_DESCRIPTION

enter image description here

What I want to do is write a query where I can pull the ticket number and item but have the item show what it actually is instead of the item code. So far I have this:

SELECT 
    TICKET_NUMBER,
    ITEM
FROM ORDER

Any help would be awesome!

Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
Infinity
  • 75
  • 1
  • 1
  • 6

1 Answers1

1
SELECT 
    [ORDER].TICKET_NUMBER,
    ITEM_DESCRIPTION.ITEM
FROM [ORDER] 
INNER JOIN ITEM DESCRIPTION ON (Order.ITEM=ITEM_DESCRIPTION.CODE)

Additional Tips:

  • "ORDER" is less than ideal for a table name because it is a SQL reserved word.

    • ID and Code seem to be redundant in your ITEM_DESCRIPTION table. Ditch the ID and make the CODE field the primary key of ITEM_DESCRIPTION.

    • The ITEM_DESCRIPTION table probably should be named "ITEM" because inevitably you will want to add more columns to describe items.

    • First Name and Last name should not be in your Order table. You should create a separate Customers table, move the name columns to the new table, and then link to it with a customer ID.

  • As sstan said in the comment. If you are going to be doing much SQL you really need to learn the syntax for JOIN operations. They are very critical to understanding SQL.

JohnFx
  • 34,542
  • 18
  • 104
  • 162
  • Thank you so much! I think "ON" was what i was looking for since I have already joined my tables together – Infinity Dec 28 '15 at 19:08
  • Reserved keywords need to be enclosed in double qutoes `"ORDER"` in (standard) SQL - which is currently the only tag of the question. –  Dec 28 '15 at 19:09