Forum Moderators: coopster

Message Too Old, No Replies

Badly Formed Query

results, but not as we would expect

         

delboy1978uk

4:36 pm on May 22, 2007 (gmt 0)

10+ Year Member



this query here is wrong, somehow

SELECT a.quantity, a.delivered, p.productname, z.quantity as deld , z.tf
FROM actualorderdetails AS a, products AS p, delnotes AS d, deldetails AS z
WHERE

d.delnoteid = 2
AND a.orderid = d.orderid
AND a.productid = p.productid
AND z.delnoteid = d.delnoteid

i expect 4 lines to be returned
but instead i get 16, with 4 of each row.

Why?

mcibor

6:36 pm on May 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To say the truth it's very hard to dissolve this query, but having just a glance, you are sure that

deldetails.delnoteid should equal 2?

For further inspection we need at least tables layout and what you want to get.

Regards
Michal

barns101

7:42 am on May 23, 2007 (gmt 0)

10+ Year Member



It sounds like you haven't restricted your results fully in the WHERE clause and so all of the rows are getting joined (4 x 4 = 16 returned).