Jump to content
php.lv forumi

mysql neatkartor vienāduy vērtību


Wuu

Recommended Posts

10 4 57 [bLOB - 86baiti] 2 1248459090

11 19 57 [bLOB - 65baiti] 2 1248459146

12 3 57 [bLOB - 47baiti] 2 1248459288

13 25 17 [bLOB - 14baiti] 1 1248459473

 

Kas jāraksta ja es vēlos lai order notiek pēc timestamp, bet tanī pašā laikā trešās kolonas vērtība neatkārtojas? Ja piemēram 57 vienreiz ir bijis, tad mysql ignorētu 57

 

Kaut kā tā :)

Edited by Wuu
Link to comment
Share on other sites

labāk sql group by paskaties ;)

function dbconn($sSrv, $sDb, $sUsr, $sPw) {  // inicializē mysql connection
@mysql_connect($sSrv, $sUsr, $sPw) or exit('<b>mysql_connect() error ' . mysql_errno() . ':</b> ' . mysql_error());
mysql_select_db($sDb) or exit('<b>mysql_select_db() error ' . mysql_errno() . ':</b> ' . mysql_error());
go('SET NAMES utf8');
}
function go($sSql) {  // izpilda mysql query
$h = mysql_query($sSql) or exit('<b>mysql_query() error ' . mysql_errno() . ':</b> ' . mysql_error() . '<br /><b>query:</b> ' . substr($sSql, 0, 1000));
return $h;
}
function esql($sSql) {  // echo sql & returned data
echo $sSql . '<br />';
$h = go($sSql);
while ($r = mysql_fetch_row($h)) echo implode(' | ', $r) . '<br />';
echo '<br />';
}

dbconn('localhost', 'test', 'root', '123');

go('DROP TABLE IF EXISTS t');
go('CREATE TABLE t (i int, j int) ENGINE=MyISAM');
go('INSERT t (i, j) VALUES (1,1),(1,1),(2,3),(4,3),(4,4)');

esql('SELECT * FROM t');
esql('SELECT DISTINCT * FROM t');
esql('SELECT * FROM t GROUP BY i');
esql('SELECT * FROM t GROUP BY j');

distinct_vs_gro_1264700180.png

Link to comment
Share on other sites

aa tad gan. es domāju, ka šajā gadījumā GROUP BY vnk paņem pirmo rindu attiecīgajā ORDER BY secībā (cik sapratu viņam ir ORDER BY. vienīgi es to neliku piemērā, lai nenovērstu uzmanību no galvenā). bet tā savādāk jau izskatās, ka viss strādā ^^

Link to comment
Share on other sites

ā tu gribi

lai distinctots ir tikai link?

hmm es īsti nezinu, var mēģināt tad apvienojot divus kvērijus ar (INNER vai OUTER) JOIN(no mysql neko nesaprotu) vai arī UNIION... kāds zinošaks labāk pastāstīs.

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