sanchoo Posted November 1, 2006 Report Share Posted November 1, 2006 ir table1 field: id table2 field:id field:a_id field:b_id ja taisu query: select table1.id from table1 t1, table2 t2 where (t1.id=t2.a_id or t1.id=t2.b_id); tad dabuuju smuki visus t1.id kuri figuree a_id vai b_id, bet kaa lai dabuu tikai tos t1.id kuri NEfiguree ne t2.a_id , ne t2.b_id ? Link to comment Share on other sites More sharing options...
bubu Posted November 1, 2006 Report Share Posted November 1, 2006 Rakstu no galvas, tāpēc varbūt kautkas neies: SELECT id FROM table1 WHERE id NOT IN (SELECT a_id FROM table2) AND id NOT IN (SELECT b_id FROM table2) vai arī (ja a_id un b_id nevar būt NULL): SELECT t1.id FROM table1 t1 LEFT JOIN table2 t2a ON t1.id=t2a.a_id LEFT JOIN table2 t2b ON t1.id=t2b.b_id WHERE t2a.a_id IS NULL AND t2b.b_id IS NULL Link to comment Share on other sites More sharing options...
sanchoo Posted November 1, 2006 Author Report Share Posted November 1, 2006 Works like a charm, paldies par palīdzību! Link to comment Share on other sites More sharing options...
andrisp Posted November 1, 2006 Report Share Posted November 1, 2006 Not sure, bet šitāds nestrādāja ? select table1.id from table1 t1, table2 t2 where (t1.id != t2.a_id AND t1.id != t2.b_id); Link to comment Share on other sites More sharing options...
bubu Posted November 1, 2006 Report Share Posted November 1, 2006 Viņam vajag lai tas id nav visu ierakstu a_id un b_id laukos, nevis viena ieraksta a_id un b_id laukos (abos vienāds). Link to comment Share on other sites More sharing options...
Recommended Posts