hmnc Posted January 19, 2006 Report Share Posted January 19, 2006 sveiki! sēžu, lauzu galvu, bet kā nesanāk tā nesanāk izdomāt loģisku queriju. tātad. piemēra pēc... 2 tabulas: table: A id, title 1, viens 2, divi 3, triis 4, chetri table: B id, a_id, default 1, 1, 0 2, 1, 1 3, 2, 0 4, 2, 1 5, 3, 0 6, 3, 0 ideja tāda - jādabūn visi ieraksti no tabulas A un tabulas B, kur tiek joinots uz a.id=b.a_id, BET - jāselekto tikai tie ieraksti B tabulā, kuriem b.default = 1, taču ja nav b.default=1 tad tiek atgriezts 0 vai dajebkas (galvenais lai tiek selektoti visi ieraksti no A). nepieciešamais gala rezultāts: a.id, b.a_id, b.id 1,1,2 2,2,4 3,3,null 4,null,null ceru, ka saprotami izskaidroju. ar joiniem man sanāca līdz tam brīdim, kad vajadzēja atgriezt defaultos no B vai arī kad B tabulā a.id netika vispār iekļauts... jau iepriekš paldies. Link to comment Share on other sites More sharing options...
[Ya] Posted January 19, 2006 Report Share Posted January 19, 2006 (edited) select A.id,A.title,B.id as bid,B.a_id,B.default from A,B where A.id=B.a_id and B.default='1' šitā vajadzētu strādāt Edited January 19, 2006 by [Ya] Link to comment Share on other sites More sharing options...
hmnc Posted January 19, 2006 Author Report Share Posted January 19, 2006 nope neiet. ja pie where norāda ka b.default jābūt 1, tad uzreiz atkrīt visi tie ieraksti no tabulas A, kuri nav reģistrēti tabulā B.. Link to comment Share on other sites More sharing options...
[Ya] Posted January 19, 2006 Report Share Posted January 19, 2006 (edited) select A.id,A.title,B.id as bid,B.a_id,B.default from B LEFT JOIN A on(B.a_id=A.id) where B.default=1 un šitā ar nešancē ? Edited January 19, 2006 by [Ya] Link to comment Share on other sites More sharing options...
v3rb0 Posted January 19, 2006 Report Share Posted January 19, 2006 [Ya]: ar where beigas neselektes visus no tables A, laikam. man liekas ka: select A.id,A.title,B.id as bid,B.a_id,B.default from B LEFT JOIN A on(B.a_id=A.id and B.default=1) bet varu kludities, neiedzilinajos un neparbaudiju. Link to comment Share on other sites More sharing options...
[Ya] Posted January 19, 2006 Report Share Posted January 19, 2006 es ar neparbaudiju, nav riktīgi laika pārbaudīt, kā nekā jāstrādā un naudiņš jāpelna, būtu vairāk laika varētu arī pārbaudīt :) Link to comment Share on other sites More sharing options...
hmnc Posted January 19, 2006 Author Report Share Posted January 19, 2006 v3rb0 - paldies. pēc nelieliem testiem atgrieza pareizi, bet vēlāk notestēšu riktīgi :) vēlreiz paldies! Link to comment Share on other sites More sharing options...
DarkSide Posted October 24, 2006 Report Share Posted October 24, 2006 [Ya]: ar where beigas neselektes visus no tables A, laikam. man liekas ka: select A.id,A.title,B.id as bid,B.a_id,B.default from B LEFT JOIN A on(B.a_id=A.id and B.default=1) bet varu kludities, neiedzilinajos un neparbaudiju. V3rb0 - Tu esi glābējs :) on(B.a_id=A.id and B.default=1) iespēju kautkā biju manuālī palaidis garām un nomocījos gandrīz visu dienu :) Paldies! Link to comment Share on other sites More sharing options...
v3rb0 Posted October 24, 2006 Report Share Posted October 24, 2006 DarkSide, paldies! un prieks ka ir arī tādi, kas lieto meklēšanu. Link to comment Share on other sites More sharing options...
Grey_Wolf Posted October 25, 2006 Report Share Posted October 25, 2006 hmnc --> LEFT JOIN vietaa patestee INNER JOIN ... (ljoti daudzos gadijumos stipri atvieglo dziivi :) ) Link to comment Share on other sites More sharing options...
DarkSide Posted October 25, 2006 Report Share Posted October 25, 2006 DarkSide, paldies! un prieks ka ir arī tādi, kas lieto meklēšanu.:) Žēl, ka te forumā nav tā kā dažās citās vietās, kad var dot punktus par labu atbildi uz jautājumu... :) Link to comment Share on other sites More sharing options...
Recommended Posts