Jump to content
php.lv forumi

kverijs ar union


anonīms

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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... :\

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...