Jump to content
php.lv forumi

Savienot 2 selectus / mysql


m8t

Recommended Posts

Tātad, pašlaik mans kods ir aptuveni šāds:

$query9 = "SELECT absx, absy FROM {$tblprefix}users WHERE absx='{$absx}' AND absy='{$absy}'"; 
$run9 = mysql_query($query9);
while($row9 = mysql_fetch_array($run9)) {
$p2_absx = $row9['absx'];
$p2_absy = $row9['absy'];
$query = "SELECT absx, absy FROM {$tblprefix}users WHERE absx='{$p2_absx}'"; 
$run = mysql_query($query);
while($row = mysql_fetch_array($run)) {
$p23_absx = $row['absx'];
}
}

^Tikai piemērs, pašlaik neko tādu nekur neizmantoju

 

Tātad, kā lai viņu pārveido vienā selectā? Es zinu, ka var kautkā, bet nemāku, vēlētos redzēt piemēru, lai varētu iemācīties, kā darīt šo lietu.

 

ps.- bija grūti paskaidrot šo, ceru ka sapratāt domu.

Link to comment
Share on other sites

Ja vajag rezultātus gan no pirmā selekta gan no otrā, tad:

SELECT absx, absy FROM {$tblprefix}users WHERE absx='{$absx}' AND absy='{$absy}'
UNION
SELECT absx, absy FROM {$tblprefix}users WHERE absx IN (
SELECT absx FROM {$tblprefix}users WHERE absx='{$absx}' AND absy='{$absy}'
);

 

Ja vajag rezultātu tikai no otrā selekta, tad:

SELECT absx, absy FROM {$tblprefix}users WHERE absx IN (
SELECT absx FROM {$tblprefix}users WHERE absx='{$absx}' AND absy='{$absy}'
);

 

P.S.

Piemērs aptuvens - neesmu testējis

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...