sql >> Database teknologi >  >> RDS >> Mysql

MySQL - Hvordan BESTILLER I EFTER RELEVANCE? INNODB tabel

version 1:

SELECT max(id) id, name
  FROM cards
 WHERE name like '%John%'
 GROUP BY name
 ORDER BY CASE WHEN name like 'John %' THEN 0
               WHEN name like 'John%' THEN 1
               WHEN name like '% John%' THEN 2
               ELSE 3
          END, name

version 2:

SELECT max(id) id, name
  FROM cards
 WHERE name like '%John%'
 GROUP BY name
 ORDER BY CASE WHEN name like 'John%' THEN 0
               WHEN name like '% %John% %' THEN 1
               WHEN name like '%John' THEN 2
               ELSE 3
          END, name



  1. fail execute statement med php og mysql

  2. PHP, MySQL, PDO-transaktioner - Stopper koden inde i try-blok ved commit()?

  3. PHPMyAdmin tvinger til at bruge ut8mb4 som standardsortering

  4. while($row =mysql_fetch_assoc($result)) - Hvordan foreacher man $row?