title: How do I select random rows in MySQL?
body: <pre><code>mytable
  
  pid name field
  === ==== =====
  1    A1   0
  2    A2   1
  3    A3   1
  4    A4   0   
  5    A5   0
  </code></pre>
  
  <p>This is my table structure. Here I want to select randomly 4 rows so I use RAND() mysql function in my query
  my questions is </p>
  
  <p>How do I pair to rows. I mean, I wanna select pid 2 and 3  always one ofter another.
  I need in bellow order. <strong>i don't want to break the pair A2 A3</strong></p>
  
  <p><code>A1 A2 A3 A4</code> or <code>A2 A3 A4 A1</code> or <code>A2 A3 A4 A5</code> or <code>A4 A5 A2 A3</code> and etc</p>
  
  <p>I used the query below but it's not working for me </p>
  
  <pre><code>SELECT * FROM mytable ORDER BY RAND() ASC limit 0,4
  </code></pre>