本文介绍了MySQL 运算符 SELECT 如何从相似的行中获得一个确切的行结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在简单的表格中有这样的SEO"行类别(id、名称、seo):
i have such 'SEO' rows in simple table categories (id, name, seo):
"abc"
"abc 22"
"abc 33"
在 MySQL 中如何使用这个查询
how in MySQL get with this query
SELECT id FROM categories WHERE seo='abc' AND LENGTH('abc')='3';"
没有找到abc 22"和abc 33"的abc"的精确行结果abc"?
one exact row result "abc" from "abc" without finding "abc 22" and "abc 33"?
推荐答案
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)
以下是 like
的行为:
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)
这篇关于MySQL 运算符 SELECT 如何从相似的行中获得一个确切的行结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!