470,833 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

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=orders_products.orders_id";
Jul 17 '05 #1
3 1671
"ph*********@comcast.net" wrote:

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!
I'm not surprised. :-)

You should definitly brush up your SQL knowledge.
$select = "SELECT * FROM orders, orders_products WHERE orders_status='2' AND
orders_id=orders_products.orders_id";


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;
Jul 17 '05 #2
JAS
> You should definitly brush up your SQL knowledge.

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


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;


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

J
Jul 17 '05 #3
JAS wrote:
You should definitly brush up your SQL knowledge.

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


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;


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


As far as I know using table aliases *is mandatory* when using multiple
tables with non unique columnnames because of ambivalence.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Chris | last post: by
reply views Thread by Mike Collins | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.