Wuu Posted January 28, 2010 Report Share Posted January 28, 2010 (edited) 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 January 28, 2010 by Wuu Quote Link to comment Share on other sites More sharing options...
anonīms Posted January 28, 2010 Report Share Posted January 28, 2010 (edited) sql distinct paskaties SELECT DISTINCT tava_57_kollona FROM tabula ORDER BY tavs_laiks DESC/ASC Edited January 28, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
2easy Posted January 28, 2010 Report Share Posted January 28, 2010 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'); Quote Link to comment Share on other sites More sharing options...
bubu Posted January 28, 2010 Report Share Posted January 28, 2010 GROUP BY lietot kopā bez agregāt-funkcijas (COUNT/SUM/utt..) ir jokaini. Rezultāti var nebūt viennozīmīgi (lasi - katrez var būt citādi). Quote Link to comment Share on other sites More sharing options...
2easy Posted January 28, 2010 Report Share Posted January 28, 2010 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ā ^^ Quote Link to comment Share on other sites More sharing options...
Wuu Posted January 30, 2010 Author Report Share Posted January 30, 2010 Mans vecais web dzinis galīgi nav domāt šitādām izvirtībām :) mysql_query('select distinct link, uid from comments... Kā piedabūti lai uid nebūtu distinctā? Quote Link to comment Share on other sites More sharing options...
waplet Posted January 30, 2010 Report Share Posted January 30, 2010 neraksti to uid tad Quote Link to comment Share on other sites More sharing options...
Wuu Posted January 30, 2010 Author Report Share Posted January 30, 2010 Bet ja vajag uid? Quote Link to comment Share on other sites More sharing options...
waplet Posted January 30, 2010 Report Share Posted January 30, 2010 ā 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. Quote Link to comment Share on other sites More sharing options...
2easy Posted January 30, 2010 Report Share Posted January 30, 2010 Mans vecais web dzinis galīgi nav domāt šitādām izvirtībām :) GROUP BY ir izvirtība? :D anyway, ja nekādi savādāk nesanāk, tad liekās/atkārtojošās vērtības atfiltrē (neņem vērā) iekš php Quote Link to comment Share on other sites More sharing options...
Wuu Posted January 30, 2010 Author Report Share Posted January 30, 2010 Nē mysql tabulas nesakarīgas... Quote Link to comment Share on other sites More sharing options...
2easy Posted January 30, 2010 Report Share Posted January 30, 2010 taisi sakarīgas tabulas ^^ 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.