Exporting from multiple tables in a db.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phatnugs420@comcast.net

    Exporting from multiple tables in a db.

    Hi all... I'm trying write a function to export certain information from a
    database that has related information in different tables. I can extract the
    info fine it's just getting it to match up where I'm having the issues. Is
    this the time for the join command? Basically I have order_id that carries
    into several tables. I need to extract that info that's related to each
    order_id. Thanks!

    $select = "SELECT * FROM orders, orders_products WHERE orders_status=' 2' AND
    orders_id=order s_products.orde rs_id";


  • Anonymous

    #2
    Re: Exporting from multiple tables in a db.

    "phatnugs420@co mcast.net" wrote:[color=blue]
    >
    > Hi all... I'm trying write a function to export certain information from a
    > database that has related information in different tables. I can extract the
    > info fine it's just getting it to match up where I'm having the issues. Is
    > this the time for the join command? Basically I have order_id that carries
    > into several tables. I need to extract that info that's related to each
    > order_id. Thanks![/color]

    I'm not surprised. :-)

    You should definitly brush up your SQL knowledge.
    [color=blue]
    > $select = "SELECT * FROM orders, orders_products WHERE orders_status=' 2' AND
    > orders_id=order s_products.orde rs_id";[/color]

    I assume what you actually mean is you have 2 tables called orders and
    orders_products , orders contains (among other data) status and id and
    orders_products contains id (and other data) and you want to do an
    equi-join (join on equal id).

    Then the SQL statement you are looking for is

    SELECT * FROM orders O, orders_products P WHERE O.status = '2' AND O.id
    = P.id;

    Comment

    • JAS

      #3
      Re: Exporting from multiple tables in a db.

      > You should definitly brush up your SQL knowledge.[color=blue]
      >
      >[color=green]
      >>$select = "SELECT * FROM orders, orders_products WHERE orders_status=' 2' AND
      >>orders_id=ord ers_products.or ders_id";[/color]
      >
      > I assume what you actually mean is you have 2 tables called orders and
      > orders_products , orders contains (among other data) status and id and
      > orders_products contains id (and other data) and you want to do an
      > equi-join (join on equal id).
      >
      > Then the SQL statement you are looking for is
      >
      > SELECT * FROM orders O, orders_products P WHERE O.status = '2' AND O.id
      > = P.id;[/color]

      Just because you use a table alias does not change the validity of the
      SQL. His SQL statement is just fine.

      J

      Comment

      • Anonymous

        #4
        Re: Exporting from multiple tables in a db.

        JAS wrote:[color=blue]
        >[color=green]
        > > You should definitly brush up your SQL knowledge.
        > >
        > >[color=darkred]
        > >>$select = "SELECT * FROM orders, orders_products WHERE orders_status=' 2' AND
        > >>orders_id=ord ers_products.or ders_id";[/color]
        > >
        > > I assume what you actually mean is you have 2 tables called orders and
        > > orders_products , orders contains (among other data) status and id and
        > > orders_products contains id (and other data) and you want to do an
        > > equi-join (join on equal id).
        > >
        > > Then the SQL statement you are looking for is
        > >
        > > SELECT * FROM orders O, orders_products P WHERE O.status = '2' AND O.id
        > > = P.id;[/color]
        >
        > Just because you use a table alias does not change the validity of the
        > SQL. His SQL statement is just fine.[/color]

        As far as I know using table aliases *is mandatory* when using multiple
        tables with non unique columnnames because of ambivalence.

        Comment

        Working...