Extended Wildcard Search in a Certain Structure of Content - sql

The content of a column contains various entrys. The structure of the contain is as follows:
A
A-B
A-B-C
Y
W-X
C-R-Z
I need a statement to search only for content separated by one dash, as well as a statement to search only for content separated by two dashes.
TIA!

For one dash:
Select * From table where col like '%[a-z]-[a-z]%'
For two dashes:
Select * From table where col like '%[a-z]--[a-z]%'

Related

How do I filter a column in a dataframe for all the entries which contain a certain substring?

I am trying to filter a column in a dataframe for all the entries which contain a certain substring:
Let's say for the above, i want to filter for all the rows that contain ada in their name. So that would be rows 5 and 6 only. I would write something like this:
SELECT * from MailList where 'ada' in email
But this doesn't work.
If this is a SQL question, you can use LIKE operator as:
... where email like '%ada%'
Note that I also added the % on it that means it will look for the ada string anywhere in the name.
as in:
blaadable#gmail.com --> matches
adable#gmail.com --> matches
ble#gmail.com.ada --> matches
You can also use it (%) only as a prefix and/or suffix. As in
... email like '%ada' or email like 'ada%' It will work accordingly.

SQL LIKE - Using square bracket (character range) matching to match an entire word

In REGEX you can do something like [a-c]+, which will match on
aaabbbccc
abcccaabc
cbccaa
b
aaaaaaaaa
In SQL LIKE it seems that one can either do the equivalent of ".*" which is "%", or [a-c]. Is it possible to use the +(at least one) quantifier in SQL to do [a-c]+?
EDIT: Just to clarify, the desired end-query would look something like
SELECT * FROM table WHERE column LIKE '[a-c]+'
which would then match on the list above, but would NOT match on e.g "xxxxxaxxxx"
As a general rule, SQL Server's LIKE patterns are much weaker than regular expressions. For your particular example, you can do:
where col not like '%[^a-c]%'
That is, the column contains no characters that are not a, b, or c.
You can use regex in SQL with combination of LIKE e.g :
SELECT * FROM Table WHERE Field LIKE '%[^a-z0-9 .]%'
This works in SQL
Or in your case
SELECT * FROM Table WHERE Field LIKE '%[^a-c]%'
I seems you want some data from database, That is you don't know exactly, You must show your column and the all character that you want in that filed.

Find substring in string

Is it possible to check if a specific substring which is in SQL Server column, is contained in a user provided string?
Example :
SELECT * FROM Table WHERE 'random words to check, which are in a string' CONTAINS Column
From my understanding, CONTAINS can't do such kind of search.
EDIT :
I have a fully indexed text and would like to search (by the fastest method) if a string provided by me contains words that are present in a column.
You can use LIKE:
SELECT * FROM YourTable t
WHERE 'random words ....' LIKE '%' + t.column + '%'
Or
SELECT * FROM YourTable t
WHERE t.column LIKE '%random words ....%'
Depends what did you mean, first one select the records that the column has a part of the provided string. The second one is the opposite.
Just use the LIKE syntax together with % around the string you are looking for:
SELECT
*
FROM
table
WHERE
Column LIKE '%some random string%'
This will return all rows in the table table in which the column Column contains the text "some random string".
1) If you want to get data starting with some letter you can use % this operator like this in your where clause
WHERE
Column LIKE "%some random string"
2) If you want to get data contains any letter you can use
WHERE
Column LIKE "%some random string%"
3)if you want to get data ending with some letter you can use
WHERE
Column LIKE "some random string%"

Query database for records with non-accented letters

I have a field in my database containing text like "Lobo de río" (note the accent on the letter "í". I need to search this column for records like '%rio%', where there is no accent on the "í". I have tried several things but have been unsuccessful.
You could look for all values that only have non-extended ascii characters (the first 128).
select *
from yourTable
where yourColumn REGEXP '[\x00-\x7F]*';

SQLite select where column does not contain certain data

ok so I have a table that looks something like this...(using pipe symbol to separate columns)
example1 url|0
example2 url|0
example3 url|1
example4 url|1,2
example5 url|1,3,6
What I am trying to do is to select all rows where column 2 does NOT contain a 1.
I cannot use != because if you look all but one of those would return data because the last 2 rows don't equal 1. I tried scouring SQLite documentation for how to go about writing the statement, but I can't find it. This is what I have so far.
select * from table_name where table_column_name[something needed here]'1';
Give that "1,2,3" et al are strings, you probably need the LIKE keyword.
select * from table_name where table_column_name NOT LIKE '%1%'
For matching a list item separated by ,, use:
SELECT * FROM table WHERE `,`||column||`,` NOT LIKE '%,1,%';
this will match entire item (ie, only 1, not 11, ...), whether it is at list beginning, middle or end.