Skip to content

Instantly share code, notes, and snippets.

@relax-more
Created September 26, 2012 10:15
Show Gist options
  • Save relax-more/3787182 to your computer and use it in GitHub Desktop.
Save relax-more/3787182 to your computer and use it in GitHub Desktop.
MySQL Random Sort
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#
<?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