SQL how to compare using a char - sql

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%'

Related

SQLite, LIKE column name

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.

SQL case unsensitive

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

Using wildcard characters while trying to convert from one datatype to another

I'm trying to run an SQL query involving converting one datatype to another.
SELECT
convert(char(12),name) as NAME
FROM
people
WHERE
convert(char(12),place) = 'Chicago'
This works. However, I'm not sure how to alter the query to use wildcard characters. I imagine it would be something like the following (which does not work in its current state) -
SELECT
convert(char(12),name) as NAME
FROM
people
WHERE
convert(char(12),place) = '%Chicago%'
Please help.
If you want to use wildcard characters, you need to use LIKE:
select convert(char(12),name) as NAME
from people
where convert(char(12),place) LIKE '%Chicago%'

how to retrieve sql column includes special characters and alphabets

How to retrieve a column containing special characters including alphabets in SQL Query. i have a column like this 'abc%def'. i want to retrieve '%' based columns from that table.
Please help me in this regard.
Is abc%def the column name? or column value? Not sure what you are asking but if you mean your column name contains special character then you can escape them which would be different based on specific RDBMS you are using
SQL Server use []
select [abc%def] from tab
MySQL use backquote
select `abc%def` from tab
EDIT:
Try like below to fetch column value containing % character (Checked, it works in Ingres as well)
select * from tab where col like '%%%'
Others suggest that like '%%%' works in Ingres. So this is something special in Ingres. It does not work in other dbms.
In standard SQL you would have to declare an escape character. I think this should work in Ingres, too.
select * from mytable where str like '%!%%' escape '!';

Android SQL statement

I'm new to SQL and I believe there is maybe a mistake.
I would search my database with
SELECT * FROM Data WHERE xx='4*'
I need all data where in colum xx is the first number 4 (string)
44545 and 493435 and 4111111 and so on with all other columns
Is that Statement ok?
You must use the LIKE syntax instead of the equality operator =:
SELECT * FROM Data WHERE xx LIKE '4%'