I want to write an SQL query using the LIKE
keyword. It should search the first character or the starting character of my column with the search parameter.
我想使用LIKE关键字编写SQL查询。它应该使用search参数搜索我的列的第一个字符或起始字符。
Is there a specific syntax for doing this?
这样做有特定的语法吗?
4 个解决方案
#1
Is this what you're looking for
这就是你要找的东西
SELECT *
FROM yourtable
WHERE yourcolumn LIKE 'X%'
This will find all rows where yourcolumn
starts with the letter X.
这将找到您的列以字母X开头的所有行。
To find all that ends with X:
要找到以X结尾的所有内容:
...
WHERE yourcolumn LIKE '%X'
...and contains an X...
......并且包含一个X ...
...
WHERE yourcolumn LIKE '%X%'
#2
Try
select * from table where column like 'c%'
where 'c' is the character you want
其中'c'是你想要的角色
#3
Here's two examples...
这是两个例子......
SELECT FirstName
FROM tblCustomer
WHERE FirstName LIKE 'B%'
The % sign is the wildcard, so this would return all results where the First Name starts with B.
%符号是通配符,因此这将返回名字以B开头的所有结果。
This might be more efficient though...
这可能会更有效......
SELECT FirstName
FROM tblCustomer
WHERE LEFT(FirstName, 1) = 'B'
#4
For a parameterized query, which you seem to have ("search the first character [...] with the search parameter"), use this:
对于您似乎具有的参数化查询(“使用搜索参数搜索第一个字符[...]”),请使用以下命令:
SELECT *
FROM yourtable
WHERE yourcolumn LIKE ? + '%'
#1
Is this what you're looking for
这就是你要找的东西
SELECT *
FROM yourtable
WHERE yourcolumn LIKE 'X%'
This will find all rows where yourcolumn
starts with the letter X.
这将找到您的列以字母X开头的所有行。
To find all that ends with X:
要找到以X结尾的所有内容:
...
WHERE yourcolumn LIKE '%X'
...and contains an X...
......并且包含一个X ...
...
WHERE yourcolumn LIKE '%X%'
#2
Try
select * from table where column like 'c%'
where 'c' is the character you want
其中'c'是你想要的角色
#3
Here's two examples...
这是两个例子......
SELECT FirstName
FROM tblCustomer
WHERE FirstName LIKE 'B%'
The % sign is the wildcard, so this would return all results where the First Name starts with B.
%符号是通配符,因此这将返回名字以B开头的所有结果。
This might be more efficient though...
这可能会更有效......
SELECT FirstName
FROM tblCustomer
WHERE LEFT(FirstName, 1) = 'B'
#4
For a parameterized query, which you seem to have ("search the first character [...] with the search parameter"), use this:
对于您似乎具有的参数化查询(“使用搜索参数搜索第一个字符[...]”),请使用以下命令:
SELECT *
FROM yourtable
WHERE yourcolumn LIKE ? + '%'