hu_ha Posted February 20, 2004 Report Share Posted February 20, 2004 ir divas tabulas: produkts: ------------------ prod_id|nos ------------------- 1 |a 2 |b 3 |c 4 |d 5 |e un pasutijums ------------------ id_pas| id_prod ------------------- 6 | 2 6 | 5 7 | 2 7 | 3 prod_id un id_prod ir tabulu sasaistes lauki. vaisaajumam buutu jaatgriezh visus produktu nosaukumus, kuri nav tabulaa pasutijums. piem, ja id_pas=6, tad jaatgriezh: a, c, d ja id_pas=7, tad : a,d,e izmeegjinaajos visaadi, bet taa arii neizdevaas. te ir dazhi varianti, kaa meegjinaaju panaakt vajadziigo rezultaatu SELECT * FROM produkts as a LEFT JOIN (select id_prod from produkts, pasut_prod where id_pas=6 and id_prod=prod_id) as b ON b.id_prod=a.prod_id WHERE b.id_prod IS NULL; vai arii: select * from produkts where prod_id not in (select id_prod from produkts, pasut_prod where id_pas=6 and id_prod=prod_id) un veel paaris varianti, tomeer rezultaata nav. paldies jau ieprieksh Link to comment Share on other sites More sharing options...
Roze Posted February 20, 2004 Report Share Posted February 20, 2004 Shitais bes subselectiem (mysql <= 4.0x): SELECT produkts.* FROM produkts LEFT JOIN pasutijums ON (produkts.prod_id=pasutijums.id_prod AND pasutijums.id_pas='6') WHERE pasutijums.id_prod IS NULL; Shitaas vareetu buut ar: SELECT * FROM produkts WHERE prod_id NOT IN (SELECT id_prod FROM pasutijums WHERE id_pas='6') Link to comment Share on other sites More sharing options...
hu_ha Posted February 20, 2004 Author Report Share Posted February 20, 2004 paldies Roze, kaarteejo reizi izruchiiji :) nedaudz pieskanjoju savaam tieshajaam vajadziibaam un aizgaaja taa lieta. laikam buus kaartiigaak jaapaurbjas sarezhgjiitaakos un specifiskaakos vaicaajumos :\ Link to comment Share on other sites More sharing options...
Roze Posted February 21, 2004 Report Share Posted February 21, 2004 Nee nu bija jau tev doma un virziens pareizs tik bik kljuudaini pierakstiits.. Anyway you're welcome :) Link to comment Share on other sites More sharing options...
Recommended Posts