Joins

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joel

    #1

    Joins


    Hi,

    Table Oelsls contains all products bought (history) table Invt contains
    the products to sell (Inventory) I'm trying with no success to list all
    products in Oelsls table (field name in both tables: part_id) that are not
    in the Invt table.

    My objective is a grid of all Special (non inventory) products.

    Can anyone produce the correct sql statement?

    Thank you.


  • Rich R

    #2
    Re: Joins


    "Joel" <joel@ecsnj.com > wrote in message
    news:mKfyd.7335 $152.4970@trndn y01...[color=blue]
    >
    > Hi,
    >
    > Table Oelsls contains all products bought (history) table Invt[/color]
    contains[color=blue]
    > the products to sell (Inventory) I'm trying with no success to list all
    > products in Oelsls table (field name in both tables: part_id) that are not
    > in the Invt table.
    >
    > My objective is a grid of all Special (non inventory) products.
    >
    > Can anyone produce the correct sql statement?
    >
    > Thank you.
    >[/color]
    Depends of the version of MySQL.

    If you don't have subqueries then

    create table BoughtItems(
    ItemNumber tinyint unsigned not null primary key);

    create table InventoryItems(
    ItemNumber tinyint unsigned not null primary key);

    insert into BoughtItems (ItemNumber)val ues(1),(2),(3), (10);
    insert into InventoryItems( ItemNumber)valu es(1),(2),(3)

    SELECT BoughtItems.Ite mNumber FROM BoughtItems
    LEFT OUTER JOIN InventoryItems on InventoryItems. ItemNumber =
    BoughtItems.Ite mNumber
    where InventoryItems. ItemNumber is null;

    If you do have subqueries, then:

    SELECT ItemNumber FROM BoughtItems where ItemNumber not in(
    SELECT ItemNumber FROM InventoryItems)

    Regards,
    Rich


    Comment

    • Joel

      #3
      Re: Joins


      Thank you Rich

      I'm not yet familiar with sub queries But your first suggestion worked like
      a charm!


      "Rich R" <rryan@cshore.c om> wrote in message
      news:ERgyd.2667 $rR5.287@newssv r31.news.prodig y.com...[color=blue]
      >
      > "Joel" <joel@ecsnj.com > wrote in message
      > news:mKfyd.7335 $152.4970@trndn y01...[color=green]
      > >
      > > Hi,
      > >
      > > Table Oelsls contains all products bought (history) table Invt[/color]
      > contains[color=green]
      > > the products to sell (Inventory) I'm trying with no success to list all
      > > products in Oelsls table (field name in both tables: part_id) that are[/color][/color]
      not[color=blue][color=green]
      > > in the Invt table.
      > >
      > > My objective is a grid of all Special (non inventory) products.
      > >
      > > Can anyone produce the correct sql statement?
      > >
      > > Thank you.
      > >[/color]
      > Depends of the version of MySQL.
      >
      > If you don't have subqueries then
      >
      > create table BoughtItems(
      > ItemNumber tinyint unsigned not null primary key);
      >
      > create table InventoryItems(
      > ItemNumber tinyint unsigned not null primary key);
      >
      > insert into BoughtItems (ItemNumber)val ues(1),(2),(3), (10);
      > insert into InventoryItems( ItemNumber)valu es(1),(2),(3)
      >
      > SELECT BoughtItems.Ite mNumber FROM BoughtItems
      > LEFT OUTER JOIN InventoryItems on InventoryItems. ItemNumber =
      > BoughtItems.Ite mNumber
      > where InventoryItems. ItemNumber is null;
      >
      > If you do have subqueries, then:
      >
      > SELECT ItemNumber FROM BoughtItems where ItemNumber not in(
      > SELECT ItemNumber FROM InventoryItems)
      >
      > Regards,
      > Rich
      >
      >[/color]


      Comment

      Working...