Hello i have a table with colums called NAME, in this colum i can have this type of name : First name Uppercase and other lower (Jack), all name uppercase (JACK), and name with space (Jack ) or (JACK ).
How can show all name than have jack in all type ?
i need to search multiple name with IN statement
i use ORACLE
Assuming SQL Server:
SELECT Name FROM Table WHERE Name LIKE '%jack%'
SELECT Name
FROM Table
WHERE UPPER(Name) LIKE '%JACK%'
will work in all SQL. In SQL Server I believe LIKE is case insensitive but it might depend on configuration settings and collation.
or maybe you need
SELECT Name
FROM Table
WHERE UPPER(TRIM(Name)) IN ('JACK','HOGAN','VICTOR')
(replace TRIM(Name) with RTRIM(LTRIM(Name)) if not using SQL Server.)
If you have a table with the list of names you can do it like this:
SELECT Name
FROM Table
JOIN NameTable ON UPPER(RTRIM(LTRIM(Table.Name))) = NameTable.Name
Related
There is some Data in the MySQL Workbench. Column name is Left , Right in one table .
Select PersonNumber,Left,Right,PhotoNumbr from Person.
This query is showing is error.
How can I fetch these records ,One thing cannot change column name in table.
Escape in square brackets the column names which are coincident with SQL Server functions:
SELECT PersonNumber, [Left], [Right], PhotoNumbr
FROM Person;
For future reference, do not name your columns using keyword or function names.
Helllo,
I have a table that has an SQL instruction as a column name. I have tried the standard SQL solutions with "limit" or [limit] but they don't work.
SELECT
limit
FROM
table
Regards
To use reserved SQL instruction words as column name, use them in backticks. Or write the table name in front:
select tbl.limit, `limit`
from
(select 1 as `limit`) tbl
What query could I use in sqlite to get the names of columns beginning with (for example) "thing" in a DB
Such as if they were formatted like this:
"thing_column1"
"thing_column2"
"thing_data"
etc.
You can use pragma_table_info() with the table's name:
SELECT name
FROM pragma_table_info('tablename')
WHERE name LIKE 'thing%'
You can use this query:
SELECT GROUP_CONCAT(name) AS columns
FROM pragma_table_info('tablename')
WHERE name LIKE 'thing%'
which returns only 1 column columns with a string value like 'thing_column1,thing_column2,thing_column3' and you can use it to construct a SELECT statement in your application.
I have a table in SQL Server DB with something like:
Name
------
phòng
phóng
phong
phao
phim
I would like to write thing like:
select * from table where name like 'pho%'
and it will return first 3 rows.
In MySQL the above script work, but not on SQL Server.
What should I do to make it work?
You need to specify that you want the LIKE comparison to be accent insensitive (and usually case insensitive as well):
select * from table
where name like 'pho%' COLLATE [Vietnamese_CI_AI]
To get a list of accent insensitive collations:
select * from fn_helpcollations()
where name like '%AI%' and name like 'viet%'
Collation Vietnamese_CI_AI is
Vietnamese, case-insensitive, accent-insensitive,
kanatype-insensitive, width-insensitive
I want to get all names starting with a specific character.
Example:
char = 'C'
names:
Chal,
Chess,
Arter,
Bain,Dave
Result: Chal, Chess
In most cases LIKE is what you need. An SQL Server example would be:
SELECT Name
FROM Names
WHERE Name LIKE 'C%'
This should work in SQL Server, MySQL, Oracle and PostGress.
You should state your Database engine for more proper answers.
SELECT * FROM table WHERE name like "C%";
Use like in where clause, eg:
WHERE COLUMN LIKE 'C%'