pro_php thread: Sql statements inside variables.
Thanks for the comments! I'll look into it.
I forgot to take out the customers table from the FROM clause, but I
originally was selecting c.name as well, but then I figured it would be lame
since you'd be extracting the same thing for every row. It'd make more
sense to just know the name ahead of time, since the customer name really
has nothing to do with how much of a particular product they ordered.
Take care,
nik
-----Original Message-----
From: David Cameron [mailto:dcameron@i...]
Sent: Wednesday, March 06, 2002 8:02 PM
To: professional php
Subject: [pro_php] RE: Sql statements inside variables.
Doh! I should have read all of your reply before I sent my email.
> SELECT p.name as ProdName,
> p.id as ProdId,
> o.quantity as OrderQuantity
> FROM customers c, products p, orders o
> WHERE o.id = $customer_order_id
> AND o.pid = p.id
This syntax works but is deprecated. The SQL-92 standard (the current
dominant standard for SQL) uses the JOIN syntax. For more complicated JOINs
you can have ambiguous statements. Also in your statement you have the
customer table in the FROM clause but don't use it. Here is a link to an
article on the two different syntaxes.
http://www.swynk.com/friends/boyle/ansijoins.asp
Anyway your statement could be rewritten as:
SELECT p.name as ProdName,
p.id as ProdId,
o.quantity as OrderQuantity
FROM products p
JOIN orders o ON
o.pid = p.id
WHERE o.id = $customer_order_id
regards
David Cameron
nOw.b2b
dcameron@i...