Blitz Posted November 14, 2006 Report Share Posted November 14, 2006 Ir šāds kverijs: SELECT P.ID, P.ARTIKULS as preces_art, F.FAILS as bilde FROM PRECES P LEFT JOIN FOTO F ON F.ISN=P.ID and F.RADIT='1' WHERE P.GRUPA='1' Piemēram ja tabulā FOTO eksistē vairāki ieraksti ar vienu un to pašu F.ISN, tad viss kverijs man atgriež divus rezultātus, respektīvi katrs P.ID itkā dublējas. Vai ir kāds veids ieviest LEFT JOIN kadus limitējošus parametrus lai atgriež vienu un tikai vienu rezultātu katram P.ID. Apmēram tabulu struktūras. -P- -F- ______________ ________________________ | ID | ARTIKULS | | ID | ISN | FAILS | RADIT | 1 234 10 1 a.jpg 1 2 324 11 1 b.jpg 1 3 123 22 2 c.jpg 1 _______________ _________________________ Augstak ir redzmas ka vis kverijas atgriezis : | ID | ARTIKULS | FAILS | 1 234 a.jpg 1 234 b.jpg 2 324 ------ 3 123 c.jpg Tad kā varētu (ja vispār var) izveidot tā, lai katram P.ID atgirez tikai vienu bildi? Link to comment Share on other sites More sharing options...
Delfins Posted November 14, 2006 Report Share Posted November 14, 2006 subselect? select fA, (select fB from B where fB = fA) from A Link to comment Share on other sites More sharing options...
Blitz Posted November 14, 2006 Author Report Share Posted November 14, 2006 apbrinojami- beidzot kautkas stradaa arii. Jaskatas kaa tik bus performances zinjaa, bet nu vaidzeja but ok. paldies. Link to comment Share on other sites More sharing options...
Delfins Posted November 14, 2006 Report Share Posted November 14, 2006 Neesmu nekad pētījis firebird, bet visās normālas RDBMS ir šitāda fīča. Par perfomancu nemāku teikt... būs 1 table scan + mazie selekti. diez ko optimizēti nav. bet kā vienīgais variants der (citu pagaidām nemaz neiedomājos) Link to comment Share on other sites More sharing options...
marrtins Posted November 16, 2006 Report Share Posted November 16, 2006 subselect? select fA, (select fB from B where fB = fA) from A a šeit nesanāks `mutiple results in singleton select` errors? Link to comment Share on other sites More sharing options...
Delfins Posted November 16, 2006 Report Share Posted November 16, 2006 Neviens nav aizliedzis ierobežot ierakstu skaitu. Link to comment Share on other sites More sharing options...
Blitz Posted November 16, 2006 Author Report Share Posted November 16, 2006 Strada loti briniskjigi un atri. Es pat nezinu vai vel butu kads efektivaks variants. SELECT P.ID, P.ARTIKULS , P.NOSAUKUMS, P.CENA, P.SKAITS, P.SV_KODS, (SELECT FIRST 1 ID FROM IPASA_CENA WHERE PRECE=P.ID ORDER BY ID DESC), (SELECT FIRST 1 ID FROM AKCIJAS WHERE PRECE=P.ID ORDER BY ID DESC), (SELECT FIRST 1 FAILS FROM FOTO WHERE ISN=P.ID ORDER BY DATUMS DESC) FROM PRECES P Link to comment Share on other sites More sharing options...
Recommended Posts