laucinieks Posted October 1, 2011 Report Share Posted October 1, 2011 Tātad, pieņemsim ir datubāzes tabula vieninieki, un ir lauki id; nosaukums; cipars; klients . Tātad es izvelku "SELECT klients FROM vieninieki"; un izvadu visus rezultātus uz ekrāna, bet ir tāda, lieta, ka ir iespējams vairākiem ierakstiem būt viens klients, un tad viņš atkārtojas, bet man vajag lai viņš tikai vienu reizi tiek izvadīts uz ekrāna. Varbūt variet norādīt pareizo virzienu? L. Quote Link to comment Share on other sites More sharing options...
codez Posted October 1, 2011 Report Share Posted October 1, 2011 Pareizais virziens ir taisīt tabulu klienti un no turienes vilkt, bet citās tabulās glabāt klienta id. Quote Link to comment Share on other sites More sharing options...
laucinieks Posted October 1, 2011 Author Report Share Posted October 1, 2011 Bet, tāpat viņš izvada man 10x vienu un to pašu klientu. L. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted October 1, 2011 Report Share Posted October 1, 2011 Pirmkārt, džoini ('joins'). Otrkārt, šamiem ir daudz veidi (left, right, inner utml.) visām dzīves situācijām. :D SQL for Beginners: Part 3 – Database Relationships Quote Link to comment Share on other sites More sharing options...
laucinieks Posted October 1, 2011 Author Report Share Posted October 1, 2011 Hmm, īsti nekad neesmu sapratis, kā ir ar tiem joiniem. Varbūt variet iedot, kaut kādu piemēru, kur ir divas tabulas, un jāizvelk vārds, no otrās tabulas, un viņš nedrīkst atkārtoties? L. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted October 1, 2011 Report Share Posted October 1, 2011 Es iedevu jau linku. Quote Link to comment Share on other sites More sharing options...
briedis Posted October 1, 2011 Report Share Posted October 1, 2011 Vizuāla JOIN'u demonstrācija: http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html Quote Link to comment Share on other sites More sharing options...
rebuilder Posted October 1, 2011 Report Share Posted October 1, 2011 (edited) Viņam tak viena tabula, pieņemot, ka nekas liels tur nav, domāju mierīgi var iztikt arī ar GROUP BY Edited October 1, 2011 by rebuilder Quote Link to comment Share on other sites More sharing options...
laucinieks Posted October 1, 2011 Author Report Share Posted October 1, 2011 (edited) Nu, tabulā ir ~10000 ieraksti, un ik dienu papildinās, ja es lietošu group by, tad viss būs labi, un nekas nebremzēs? L. Edited October 1, 2011 by laucinieks Quote Link to comment Share on other sites More sharing options...
rebuilder Posted October 1, 2011 Report Share Posted October 1, 2011 (edited) Nu, Tev pati tabula jau ir nepareiza un kā jau minēja, vajadzētu 2. Tā kā, ja netaisies labot to, tad lieto GROUP BY vai arī veido pareizu DB struktūru ;) Edited October 1, 2011 by rebuilder 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.