2

I'm new to the T-SQL language as my office is now using the Microsoft SQL Server Management Studio.

I am trying to pull all of the info from a large table but only when the item number shows in 1 column in another table. I have a small subset of items and I need to pull all the info from another that is more robust.

The small set table is named Itemmaster (IM) and has the following columns:

IM.item number
IM.description
IM.manuf
IM.item_Code

The second table, named Item_Directory (ID), has all of the info about the items including items with the same item codes. I want to pull all of the data from the Item_Directory where:

ID.item_Code = IM.Item_Code

No matter how I "think" it should be written, I seem to be wrong. I know this will probably be a simple formula but I'm still learning T-SQL.

My previous employer used Oracle and that just seemed easier for me to learn. Of course I am completely self taught so forgive me if I don't seem to know some of the basics.

Thanks for the suggestions.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kelly
  • 21
  • 1
  • Please include the code you have written. – SteveB Dec 10 '18 at 15:03
  • SQL Server Management Studio (SSMS) isn't SQL Server; it's an application you use to interact with SQL Server. This is an important distinction you need to be aware of. Based on your description, however, you seem to be describing a "simple" `JOIN` and `WHERE`; which is unlikely to have much variance different in whether written in T-SQL or PL/SQL. – Thom A Dec 10 '18 at 15:07
  • Are you trying to use an INNER JOIN or something? That would be the normal way to do it e.g. something like `SELECT * FROM itemMaster IM INNER JOIN Item_Directory ID ON IM.Item_code = ID.item_code` Please show us the exact code you tried to use and what problem/error you encountered. – ADyson Dec 10 '18 at 15:08

1 Answers1

1
select IM.item number,
     IM.description,
     IM.manuf,
     IM.item_Code,
     ID.*
From itemmaster IM
     inner join item_details ID
          on ID.item_Code = IM.Item_Code
Matt
  • 782
  • 4
  • 11
  • Yes, this should do the trick! Note that this query will probably also work in Oracle. The OP may have been using the "old" query syntax in Oracle, not the "new" ANSI join syntax (more on this on https://stackoverflow.com/questions/18891148/oracle-joins-comparison-between-conventional-syntax-vs-ansi-syntax) – johey Dec 10 '18 at 15:16
  • You are close but read more carefully. `The second table, named Item_Directory (ID), has all of the info about the items including items with the same item codes.` **I want to pull all of the data from the Item_Directory** – Juan Carlos Oropeza Dec 10 '18 at 15:16
  • @JuanCarlosOropeza: I see `ID.*` in Matt's query for all data from Item_Directory...... – HardCode Dec 10 '18 at 19:27
  • @HardCode the table is `Item_Directory` but is called `item_details` here. And OP only want ID fields so the rest arent necesary – Juan Carlos Oropeza Dec 10 '18 at 19:31
  • @JuanCarlosOropeza: Yes, I see now. Matt has a typo in the Item_Directory table name. – HardCode Dec 10 '18 at 19:34