Created
September 26, 2012 10:15
-
-
Save relax-more/3787182 to your computer and use it in GitHub Desktop.
MySQL Random Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
a.value AS x, b.value AS y | |
FROM | |
$table$ a | |
LEFT JOIN $table$ b ON (a.id = b.id) | |
WHERE a.category = #categoryA# | |
AND b.category = #categoryB# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE sqlMap | |
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" | |
"http://ibatis.apache.org/dtd/sql-map-2.dtd"> | |
<sqlMap namespace="snippet"> | |
<select id="snippetRandomSort"> | |
SELECT | |
a.value AS x, b.value AS y | |
FROM | |
$table$ a | |
LEFT JOIN $table$ b ON (a.id = b.id) | |
WHERE a.category = #categoryA# | |
AND b.category = #categoryB# | |
<!-- point:'ORDER BY rand()' --> | |
<isNotEqual property="dataLimit" compareValue="-1"> ORDER BY rand() LIMIT #dataLimit#</isNotEqual> | |
</select> | |
</sqlMap> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment