Is there a combination of LIKE and IN in SQL

0 votes

Unfortunately, I frequently utilize "LIKE" criteria in SQL because of databases that blatantly disregard all normalization rules. Right now, I can't change it. However, that has no bearing on the inquiry. In addition, I frequently utilize conditions like WHERE something in (1,1,2,3,5,8,13,21) to make my SQL queries easier to comprehend and more flexible.

Is it possible to combine these two things without having to create laborious sub-selects?

Instead of this, I would prefer something as simple as WHERE something LIKE ('bla%', '%foo%', or 'batz%'):

WHERE something LIKE 'bla%'
OR something LIKE '%foo%'
OR something LIKE 'batz%'

I'm working with SQL Server and Oracle here but I'm interested if this is possible in any RDBMS at all. Can someone please help me with this?

Sep 17, 2022 in Database by Kithuzzz
• 38,020 points
4,328 views

1 answer to this question.

0 votes

There is no LIKE & IN combination in either SQL or TSQL (SQL Server), much less PLSQL (Oracle). The fact that Full-Text Search (FTS) is the suggested substitute contributes to this.

The CONTAINS keyword is supported by both Oracle and SQL Server FTS implementations, however, the syntax is still a little different:

Oracle:

WHERE CONTAINS(t.something, 'bla OR foo OR batz', 1) > 0

SQL Server:

WHERE CONTAINS(t.something, '"bla*" OR "foo*" OR "batz*"')

I hope this helps you. 

If you need to know more about SQL, it is recommended to go for the SQL Course today.

answered Sep 18, 2022 by narikkadan
• 63,720 points

Related Questions In Database

0 votes
1 answer

What do ‘Record’, ‘Field’ and ‘Table’ mean in terms of a database?

You can refer to the following definitions ...READ MORE

answered Nov 12, 2018 in Database by Sahiti
• 6,370 points
21,849 views
0 votes
1 answer

What is a Join in terms of database?

JOINS are used to combine rows from ...READ MORE

answered Nov 13, 2018 in Database by DataKing99
• 8,250 points
941 views
0 votes
1 answer

Ordering by the order of values in a SQL IN() clause

Use MySQL's FIELD() function: SELECT name, description, ... FROM ... WHERE id ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,060 points
5,125 views
0 votes
1 answer

What is the definition of cardinality in SQL?

Cardinality is defined as the "number of ...READ MORE

answered Feb 15, 2022 in Database by Neha
• 9,060 points
1,804 views
0 votes
0 answers

What is the Oracle equivalent of SQL Server's IsNull() function?

In SQL Server we can type IsNull() ...READ MORE

Sep 4, 2022 in Database by Kithuzzz
• 38,020 points
523 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
773 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,070 points
475 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,060 points
998 views
0 votes
1 answer

Is there a Boolean data type in Microsoft SQL Server like there is in MySQL?

The BIT datatype can be used to ...READ MORE

answered Sep 15, 2022 in Database by narikkadan
• 63,720 points
2,395 views
0 votes
1 answer

What is the use of a cursor in SQL Server?

Instead of receiving a result set as ...READ MORE

answered Sep 13, 2022 in Database by narikkadan
• 63,720 points
667 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP