7924 Posted October 28, 2007 Report Share Posted October 28, 2007 (edited) Tātad man ir tabulas: Tb1: Id | name1 ----+--------- 1 | bla1 2 | bla2 3 | bla3 4 | bla4 5 | bla5 Tb2: Id | name2 ----+--------- 1 | zla1 2 | zla2 3 | zla3 4 | zla4 5 | zla5 Tb3: Id | name2 ----+--------- 1 | Tla1 2 | Tla2 3 | Tla3 4 | Tla4 5 | Tla5 un man vajag, lai rezultāts būtu šāds: Tb4: Id | jauna kolonna |tb1.id ----+-------------------+--------- 1 | zla1 | 1 2 | Tla1 | 1 3 | zla2 | 2 4 | Tla2 | 2 5 | zla3 | 3 6 | Tla3 | 3 7 | zla4 | 4 8 | Tla4 | 4 9 | zla5 | 5 10 | Tla5 | 5 Iegūtajā tabulā (tb4) tiek apvienoti TB3 un Tb4 dati viena kolonā: kur tb1.id=tb2.id OR tb1.id=tb3.id. Kā to var dabūt gatavu? paldies! Edited October 28, 2007 by 7924 Link to comment Share on other sites More sharing options...
bubu Posted October 28, 2007 Report Share Posted October 28, 2007 Neredzu apvienošanas sistēmu, tb. nesaprotu to tavu OR izteiksmi. Link to comment Share on other sites More sharing options...
7924 Posted October 28, 2007 Author Report Share Posted October 28, 2007 apvienošanas sistēma ir tb1. tabulai tiek piemekleti citu tabulu id lauki, kuros ir tada pati id vertiba. piemeram: SELECT Tb1.id, Tb1.name1, Tb2.id, Tb2.name2, Tb3.id, Tb3.name FROM Tb1 JOIN Tb2, Tb2 where Tb1.id=Tb2.id OR Tb1.id=Tb3.id rezultats bus apmēram tāds, ka name1, name2 un name 3 bus katrs savā kolonā, bet man to visu vajag vienā dabūt! Link to comment Share on other sites More sharing options...
Gints Plivna Posted October 28, 2007 Report Share Posted October 28, 2007 SELECT tb2.name, tb1.id FROM tb1, tb2 WHERE tb1.id = tb2.id UNION ALL SELECT tb3.name, tb1.id FROM tb1, tb3 WHERE tb1.id = tb3.id tb4.id varētu tā kā izmantot auto_increment, es pieņemu, ka nav svarīgs idu sakārtojums? Gints Plivna http://datubazes.wordpress.com Link to comment Share on other sites More sharing options...
7924 Posted October 28, 2007 Author Report Share Posted October 28, 2007 Perfekti, Gints, Paldies! Link to comment Share on other sites More sharing options...
Recommended Posts