本文介绍了SQL SELECT WHERE行包含单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从包含单词limit 1
的行中进行选择,并将其回显.
i need to select from row where contains word limit 1
, and echo it out.
例如,我在行类别中的名称大于1000 cars
,而200
具有相同的名称,我只想从每辆汽车中选择一个.
So for example, i have in row categories more than 1000 cars
which 200
with the same name, i only want to select from each car only one.
SELECT * FROM brands
WHERE car (bmw,audi,mercedes )
并按最新添加的内容排序
And sort by newest added
推荐答案
无重复
您要DISTINCT或GROUP BY mysql语句:
No duplicates
You want to DISTINCT or GROUP BY mysql statement:
- DISTINCT: http://www.w3schools.com/sql/sql_distinct.asp
- 分组依据: http://www.w3schools.com/sql/sql_groupby.asp
- DISTINCT: http://www.w3schools.com/sql/sql_distinct.asp
- GROUP BY: http://www.w3schools.com/sql/sql_groupby.asp
声明:
SELECT DISTINCT(name) FROM cars
或
SELECT name FROM cars GROUP BY name
不返回重复的名称
如其他答案所示,您可以使用WHERE IN过滤一组数据:
As shown in other answers you can use WHERE IN to filter on an set of data:
WHERE `column` IN ('item`1', 'item2', ..)
您还可以使用它来子查询:
you can also use this to subquery:
SELECT * FROM cars WHERE brandId IN (SELECT Id FROM brands WHERE name IN ('BMW', 'Volkwagen', ..)
参考: http://www.w3schools.com/sql/sql_in.asp
这篇关于SQL SELECT WHERE行包含单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!