Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Operator MySQL PILIH bagaimana cara mendapatkan satu hasil baris yang tepat dari baris yang serupa?

create table stuff
(   id int auto_increment primary key,
    seo varchar(100) not null
    -- unique key (seo) not a bad idea
);

insert stuff (seo) values ('abc'),('abc7'),('kitty likes abc'),('abc and more abc'),('kittens');
insert stuff (seo) values ('abc at beginning'),('frogs'),('and at the end abc'),('qwertyabcqwerty');


select id from stuff where seo='abc';
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.02 sec)

Begini caranya like berperilaku:

select * from stuff where seo like '%abc';
+----+--------------------+
| id | seo                |
+----+--------------------+
|  1 | abc                |
|  3 | kitty likes abc    |
|  4 | abc and more abc   |
|  8 | and at the end abc |
+----+--------------------+
4 rows in set (0.00 sec)

select * from stuff where seo like 'abc%';
+----+------------------+
| id | seo              |
+----+------------------+
|  1 | abc              |
|  2 | abc7             |
|  4 | abc and more abc |
|  6 | abc at beginning |
+----+------------------+
4 rows in set (0.00 sec)

select id,seo from stuff where seo like '%abc%';
+----+--------------------+
| id | seo                |
+----+--------------------+
|  1 | abc                |
|  2 | abc7               |
|  3 | kitty likes abc    |
|  4 | abc and more abc   |
|  6 | abc at beginning   |
|  8 | and at the end abc |
|  9 | qwertyabcqwerty    |
+----+--------------------+
7 rows in set (0.00 sec)


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Mengalami masalah saat menjalankan Rails di Ubuntu

  2. Algoritma Untuk Memilih Tempat Paling Populer dari Database

  3. Sistem Antrian PHP dengan Codeigniter. BAGAIMANA?

  4. fungsi mysql_escape_string() tidak digunakan lagi gunakan mysql_real_escape_string() Codeigniter

  5. Dapatkan catatan kosong menggunakan SQL