Page 1 of 1
where is my error in this sql query
Posted: Tue Dec 06, 2005 10:31 pm
by jaylin
Code: Select all
$sql = "SELECT o.name as custname, od.* " .
"FROM tblorder as o, orderdetail od, weekly as w " .
"WHERE o.orderid = od.orderid and od.productid = w.id" .
"ORDER BY o.orderid DESC";
regards,
Re: where is my error in this sql query
Posted: Tue Dec 06, 2005 10:42 pm
by neophyte
jaylin wrote:Code: Select all
$sql = "SELECT o.name as custname, od.* " .
"FROM tblorder as o, orderdetail od, weekly as w " .
"WHERE o.orderid = od.orderid and od.productid = w.id" .
"ORDER BY o.orderid DESC";
regards,
No need to concatenate at line breaks. "." doesn't concatenate. ".." would be good form.
Code: Select all
"SELECT o.name as custname, od.* FROM tblorder as o, orderdetail od, weekly as w WHERE o.orderid = od.orderid and od.productid = w.id ORDER BY o.orderid DESC";
Some one correct me if I'm wrong, queries from mutliple tables should be "JOIN" somehow. 'w' is not in your select statement.
Hope that gets you started.
Posted: Tue Dec 06, 2005 11:02 pm
by josh
I think it's the way he's joining it, if the OP can show us the structure of the tables and exactly what he's trying to accomplish we can probably work something out, this should be in 'Databases' forum BTW
Re: where is my error in this sql query
Posted: Wed Dec 07, 2005 2:39 am
by Chris Corbyn
neophyte wrote: "." doesn't concatenate. ".." would be good form.
It's a single dot to concatenate.
Code: Select all
echo "foo"."bar"; //Correct
echo "foo".."bar"; //Wrong
Yeah you're right, you don't need it just to use line breaks

Posted: Wed Dec 07, 2005 2:42 am
by Wayne
Code: Select all
$sql = "SELECT o.name as custname, od.* " .
"FROM tblorder as o, orderdetail od, weekly as w " .
"WHERE o.orderid = od.orderid and od.productid = w.id" .
"ORDER BY o.orderid DESC";
you should try and use JOINs depending on what you are trying to achieve, as doing it this way if there are no details for the orderdetail or weekly tables to match the WHERE clauses it will leave that whole record out.
but that aside in your sql you need to change
orderdetail od in your
FROM to be
orderdetail as od
Posted: Wed Dec 07, 2005 2:43 am
by Chris Corbyn
Like jshpro2 says. Theres no syntax error so perhaps if you explain what the problem is
Note: Am i right in thinking you're trying to join using two foreign keys and no primary?
Posted: Wed Dec 07, 2005 2:46 am
by Chris Corbyn
Wayne wrote:but that aside in your sql you need to change orderdetail od in your FROM to be orderdetail as od
Not true. That's just shorthand SQL for aliasing
Is the same as
Moved to databases
EDITTED QUERIES, DONE THEM IN THE SELECT NOT FROM

FIXED
Re: where is my error in this sql query
Posted: Wed Dec 07, 2005 6:11 am
by sheila
jaylin wrote:Code: Select all
$sql = "SELECT o.name as custname, od.* " .
"FROM tblorder as o, orderdetail od, weekly as w " .
"WHERE o.orderid = od.orderid and od.productid = w.id" .
"ORDER BY o.orderid DESC";
The only error I see is no space at the end of the 3rd line, after w.id
FWIW I would format it this way,
Code: Select all
$sql = "SELECT o.name as custname, od.* "
. " FROM tblorder as o, orderdetail od, weekly as w "
. " WHERE o.orderid = od.orderid and od.productid = w.id"
. " ORDER BY o.orderid DESC";
Line up the . and always add a space after the first double quote.