Thursday, 15 April 2010

mysql - Repeated Rows Sql Query -



mysql - Repeated Rows Sql Query -

i running query , getting duplicated rows. dont understand why is. here query:

select c.fname, p.productname, s.description, s.quantity, s.price customers c, products p, sellers s, requests r c.id = s.cid , p.productid = s.productid , r.productid = s.productid , r.c_id = 3 , r.matchtype = 'price' order s.price asc

=======edit=======

okay here edit of values in requests table looks like. note: cid 2=daz(generally seller), 3=paul (generally purchase guy) , 5= compny1 (generally seller) note: product id 1= apple, product id 2=pear, productid 3= berries, product id4=orange

the request table looks after selecting records matchtype=price , cust id=3:

requestid | cid | productid | quantity | cost | matchtype ------------------------------------------------------------------ 1 3 1 3.0 2.00 cost 3 3 4 4.0 2.50 cost 4 3 3 2.5 2.00 exact 5 3 2 3.0 3.50 exact 6 3 3 3.0 2.00 exact 7 3 1 10.0 7.00 cost

and here sellers table

promotionid | cid | productid | quantity | cost | description ------------------------------------------------------------------ 1 2 4 5.0 2.99 oranges 2 2 3 1.5 1.00 hand strawberries 3 2 3 2.5 2.00 l stawberries 4 2 2 3.0 3.00 pear 5 5 1 5.0 5.00 royal apples fm appleco. 6 2 1 6.0 5.50 sweetness apples

after running query have tried both suggested joins , 1 in question maintain getting output

fname productname description quantity cost daz oranges fresh , sweetness oranges. 5.0 2.99 compny1 apple royal apples fm appleco. 5.0 5.00 compny1 apple royal apples fm appleco. 5.0 5.00 daz apple sweetness apples 6.0 5.50 daz apple sweetness apples 6.0 5.50

i don't why recieving rows repeating. requested product id must = sellers product id match requested products available products , customerid selected in case 3...

i dont why lastly 4 records repeat them self? why may be?? technically speaking 4 records should shown. i.e. records on rows.. 1,2 , 3

suggestion/observation okay, after having looked @ this... think rows repeated because productid1=apple has been requested same client twice different quantities???

requestid | cid | productid | quantity | cost | matchtype ------------------------------------------------------------------ 1 3 1 3.0 2.00 cost 7 3 1 10.0 7.00 cost

your need utilize inner bring together "filtering" rows. seek this:

select c.fname, p.productname, s.description, s.quantity, s.price requests r inner bring together sellers s on r.productid = s.productid inner bring together products p on p.productid=s.productid inner bring together customers c on c.id=s.cid r.c_id = 3 , r.matchtype='price' order s.price asc

hope don't have error here (its late here), main idea. columns exist in 2 tables , wish utilize filtering utilize inner join, filtering 1 table utilize clause .. (that theory on 1 leg) ...

--- edit ----

this query can show diffidence between requests ...

select c.fname, p.productname, s.description, s.quantity, s.price, r.demandid 'request id' requests r inner bring together sellers s on r.productid = s.productid inner bring together products p on p.productid=s.productid inner bring together customers c on c.id=s.cid r.c_id = 3 , r.matchtype='price' order r.demandid s.price asc

mysql sql records

No comments:

Post a Comment