Sasa Posted July 17, 2009 Report Share Posted July 17, 2009 kas viņam nepatīk? SELECT * FROM product WHERE ID IN ( SELECT accessories.product_id, details.product_id FROM accessories, details WHERE accessories.product_id = details.product_id ) LIMIT 0 , 30 Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 17, 2009 Report Share Posted July 17, 2009 Nepatīk tas, ka apakšvaicājums atgriež divus laukus. sanāk, ka WHERE ID IN ( vērtību pārīšu uzskaitījums) Vajag lai apakšvaicājums atgrieztu ierakstus pa vienam laukam. Quote Link to comment Share on other sites More sharing options...
Sasa Posted July 17, 2009 Author Report Share Posted July 17, 2009 bet to ko es esmu mēģinājis panākt, var kaut kādā veidā vispār izdarīt? Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted July 17, 2009 Report Share Posted July 17, 2009 kādā veidā vispār izdarīt? Visparastakais JOIN vaicajums .. preciizak dubultais Joins .. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 17, 2009 Report Share Posted July 17, 2009 Nav īsti skaidrs, ko Tu esi mēģinājis panākt :) Quote Link to comment Share on other sites More sharing options...
Sasa Posted July 17, 2009 Author Report Share Posted July 17, 2009 Es gribu paskatīties vai produkta ID tiek sastapts tajās abās tabulās. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 17, 2009 Report Share Posted July 17, 2009 Atbilde vēl aizvien nav viennozīmīga :) Abās - nozīmē, ka gan vienā, gan otrā? Vai abās nozīmē vismaz vienā? Līdz ar to vai nu: SELECT * FROM product WHERE id IN ( SELECT product_id FROM accessories WHERE accessories.product_id = product.id ) AND id IN ( SELECT product_id FROM details WHERE details.product_id = product.id ) vai arī: SELECT * FROM product WHERE id IN ( SELECT product_id FROM accessories WHERE accessories.product_id = product.id ) OR id IN ( SELECT product_id FROM details WHERE details.product_id = product.id ) Quote Link to comment Share on other sites More sharing options...
Sasa Posted July 17, 2009 Author Report Share Posted July 17, 2009 man tas produkta ID jāsastop gan accessories tabulā, gan details tabulā, un tikai tad es varu pildīt darbības tālāk. Izdomāju šo fīču tamdēļ, lai mans produktu list's aizpildās tikai ar tiem produktiem kuriem ir specene pievienota. Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 17, 2009 Report Share Posted July 17, 2009 Tātad, ja man ir tabula product: 1 2 3 4 Tabula accessories: 1 2 3 Tabula details: 2 3 4 Tu gribi, lai tas selekts izvada: 2 3 Vai ne? Faktiski derēja arī tavs pirmais vaicājums - vienkārši vajadzēja, lai izvada tikai vienu lauku tas subselects (un pilnīgi vienalga, vai details, vai accessories id tiktu izvadīts): SELECT * FROM product WHERE ID IN ( SELECT accessories.product_id FROM accessories, details WHERE accessories.product_id = details.product_id ) Quote Link to comment Share on other sites More sharing options...
Sasa Posted July 17, 2009 Author Report Share Posted July 17, 2009 jā, lai vai kā šis querijs nostrādāja: SELECT * FROM product WHERE id IN ( SELECT product_id FROM accessories WHERE accessories.product_id = product.id ) AND id IN ( SELECT product_id FROM details WHERE details.product_id = product.id ) paldies, Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 17, 2009 Report Share Posted July 17, 2009 izpēti tikai ar EXPLAIN, kurš no abiem ir labāks: SELECT * FROM product WHERE id IN ( SELECT product_id FROM accessories WHERE accessories.product_id = product.id ) AND id IN ( SELECT product_id FROM details WHERE details.product_id = product.id ) vai šitas (man aizdomas, ka labāks): SELECT * FROM product WHERE ID IN ( SELECT accessories.product_id FROM accessories, details WHERE accessories.product_id = details.product_id ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.