smarty Posted May 23, 2005 Report Share Posted May 23, 2005 kaa var atlasiit tabulas ierakstus kur kaada kolonna nesatur kaadu noteiktu veertiibu? Pimeeram. 1. tabula mashina_id usera_id mashina_marka 2. tabula usera_mashinas_id mashinas_id Jaatlasa ieraksti, kur atbilstoši laukos usera_id ir 33, bet mashinas_marka nav 'zhigulis' Link to comment Share on other sites More sharing options...
v3rb0 Posted May 23, 2005 Report Share Posted May 23, 2005 par sql un where esi kādreiz dzirdējis? select tiri piri.. from .. where usera_id=33 and mashinas_marka <> "zhigulis" Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 SELECT tabula1.* FROM tabula1 JOIN tabula2 ON mashina_id = mashinas_id WHERE usera_mashinas_id=33 AND mashina_marka!='zhigulis' Link to comment Share on other sites More sharing options...
smarty Posted May 23, 2005 Author Report Share Posted May 23, 2005 (edited) mmm nee, neveiksmiigs piemeers, izdomaashu savaadaaku... Edited May 23, 2005 by smarty Link to comment Share on other sites More sharing options...
hu_ha Posted May 23, 2005 Report Share Posted May 23, 2005 ha viss prikols sleepaa tajaa != es kkaa domaaju ka ir <> 17821[/snapback] nu != un <> ir viens un tas pats, cik man zināms Link to comment Share on other sites More sharing options...
smarty Posted May 23, 2005 Author Report Share Posted May 23, 2005 (edited) izdomaaju labaaku piemeeru 1. tabula_1 maajas_id iela_id maajas_adrese 2. tabula_2 sarga_majas_id sarga_id Jaatlasa taas maajas, kuraam nav sargs ar kaut kaadu id un atrodas uz ielas ar kkaadu id (sargs var buut vairaakaam maajaam un vairaakaam maajaam var buut vairaaki sargi) meegjinaaju shaadi bet tas atlasa visas, kur ir sargs SELECT maajas_adreseFROM tabula_1 JOIN tabula_2 ON sarga_majas_id = maajas_id WHERE sarga_majas_id = '7' AND iela_id != '99' GROUP BY maajas_id Edited May 23, 2005 by smarty Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 SELECT tabula_1.* FROM tabula_1 JOIN tabula_2 ON sarga_majas_id = maajas_id WHERE sarga_id != 123123 AND iela_id != 12444 Link to comment Share on other sites More sharing options...
smarty Posted May 23, 2005 Author Report Share Posted May 23, 2005 nu kaa, man atlasa tikai tos ierakstus, kur ir taada un taada iela un nav taads un taads sarga id, bet nevajag arii atlasiit taas maajas, kuras nav atlasiitas peec ieprieksheejaa kriteerija laikam vajadzees select no select, ja? Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 Ā, neizlasīju pareizi tavu iepriekšējo postu. Tātad tev vajag tās mājas, kuras nesargā konkrēts sargs, un kuras atrodas uz konkrētas ielas, ja? (iepriekš sapratu, ka neatrodas uz konkrētas ielas) Tad: SELECT tabula_1.* FROM tabula_1 JOIN tabula_2 ON sarga_majas_id = maajas_id WHERE sarga_id != 123123 AND iela_id = 12444 (atlika tik vien != nomainīt ar = vienā vietā) Link to comment Share on other sites More sharing options...
smarty Posted May 23, 2005 Author Report Share Posted May 23, 2005 bet shaa vai taa atlasa visas. es taa padomaaju, ka taa struktuura liidziiga kaa galerijaam. tjip jaatalasa galerijas kur nav kkaada bilde :) taa man skjiet vienkaarshaak saprast. respektiivi peec analoga kverija man izvada visas galerijas Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 kā atlasa visas? Man ir šitādas te tabulas uztaisītas: mysql> select * from tabula_1; +-----------+---------+---------------+ | maajas_id | iela_id | maajas_adrese | +-----------+---------+---------------+ | 1 | 2 | lielaa | | 2 | 2 | lielaa2 | | 3 | 4 | mazaa | | 4 | 4 | mazaa2 | +-----------+---------+---------------+ 4 rows in set (0.10 sec) mysql> select * from tabula_2; +-----------------+----------+ | sarga_maajas_id | sarga_id | +-----------------+----------+ | 1 | 1 | | 3 | 2 | | 2 | 3 | +-----------------+----------+ 3 rows in set (0.04 sec) Izdaru kveriju: mysql> SELECT tabula_1.* -> FROM tabula_1 JOIN tabula_2 ON sarga_maajas_id = maajas_id -> WHERE sarga_id != 1 AND iela_id = 2; +-----------+---------+---------------+ | maajas_id | iela_id | maajas_adrese | +-----------+---------+---------------+ | 2 | 2 | lielaa2 | +-----------+---------+---------------+ 1 row in set (0.00 sec) Manuprāt viss kā vajag. Link to comment Share on other sites More sharing options...
Recommended Posts