anonīms Posted May 25, 2009 Report Share Posted May 25, 2009 Kapēc man neizvelk otru reitingu? $nemam_reitingu = mysql_query("(SELECT reitings AS km1_reitings FROM ".PREFIX."komandas WHERE id = '".$km1."') UNION (SELECT reitings AS km2_reitings FROM ".PREFIX."komandas WHERE id = '".$km2."')") OR DIE(mysql_error()); $nemam_reitingu = mysql_fetch_array($nemam_reitingu); Errorus neizmet. Quote Link to comment Share on other sites More sharing options...
marcis Posted May 25, 2009 Report Share Posted May 25, 2009 Priekškam tur vispār union? SELECT lauks FROM `tabula` WHERE id IN (1, 2) Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted May 25, 2009 Report Share Posted May 25, 2009 Atceramies, ka UNION atgriež tikai atšķirīgās vērtības, tāpēc, ja abi SELECT vaicājumi atgriež vienu un to pašu vērtību, tad rezultātā var iegūt tikai vienu vērtību. Lai garantēti dabūtu abu SELECT vaicājumu vērtības, tad jālieto UNION ALL. Sīkāk par kopu operātoriem, tai skaitā UNION šeit. Nu un protams, kā jau norādīja iepriekšējais atbildētājs, UNION nav vienīgā iespēja. Gints Plivna http://datubazes.wordpress.com Quote Link to comment Share on other sites More sharing options...
anonīms Posted May 25, 2009 Author Report Share Posted May 25, 2009 $nemam_reitingu = mysql_query("SELECT reitings as km1_rating FROM ".PREFIX."komandas WHERE id = $km1 UNION ALL SELECT reitings as km2_rating FROM ".PREFIX."komandas WHERE id = $km2") or die(mysql_error()); Tāpat atgriež tikai pirmo... :\ Quote Link to comment Share on other sites More sharing options...
bubu Posted May 25, 2009 Report Share Posted May 25, 2009 anonīms - tev nevajag tur UNION'u lietot. Paskaties, ko marcis ir uzrakstījis. 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.