Defining a Value Set in SQLite Databases: IN and SELECT Operators

Hello, visitor of the ZametkiNaPolyah.ru website ! We continue to study databases and our

acquaintance with the SQLite3 library . In this entry, we will talk about using the SQL IN operator and the SELECT command in SQLite databases . The IN operator allows you to select data, and the rows will be selected based on a comparison of column values ​​with a predetermined set, which is specified in the IN operator. Often you can find SELECT subqueries using the IN operator, but we will talk about this in another entry.

From this post you will learn:

  • how the SQL IN operator allows you to define a set of values ​​against which rows will be compared when querying a database;
  • see an example of using IN and SELECT in SQLite3 databases;
  • and at the end of the article you will find information about which commands, in addition to SELECT, can be used with the IN operator.

 

Contents of the article:

  • 1 How to Define a Set of Values ​​in SQLite Databases Using the IN Operator and the SELECT Command
  • 2 Examples of using IN and SELECT operators in SQLite3 databases
  • 3 Using the IN Operator with Other SQLite3 Commands
  • Defining a Value Set in SQLite Databases

How to Define a Set of Values ​​in SQLite Databases Using the IN Operator and the SELECT Command

There are situations when we need to select data from a SQLite database not in a range, but by a pre-known set of values . Such a set of values ​​allows us to define the SQL operator IN together with the SELECT command . The SQL SELECT query can use the IN operator not only to define a pre-known set of values, but to create a subquery when the values ​​are unknown, but more on that in another part of the topic.

Perhaps that’s all you need to know about using the IN operator and the SELECT command , now we can practice writing a SELECT query with the IN operator and try to define our own value sets .

Examples of using IN and SELECT operators in SQLite3 databases

Let’s try to define a set of IN values. To do this, we will create a table in the SQLite database using the CREATE command :

 

here is nothing unusual in the  table created: we ensured data integrity using table-level constraints and column-level constraints , and we created an index gambling number data on the table using the PRIMARY KEY constraint . Now let’s fill the table with data , for this there is an INSERT command :

gambling number data

Now that we have the I N operator and SELECT command example , let’s write a SQL statement that will only show rows from a specific set of values :

[php]

SELECT * FROM table1

WHERE id NOT IN (1,3,5,7);

2|Sumkin Denis|Lawyer|m|35040.9

4|Markova Irina|Accountant|w|31200.1

6|Mikhailova Lyubov|Secretary|f|16200.1

8|Mikhailova Lyubov|Document manager|f|21200.1

[/php]

Using the IN Operator with Other SQLite3 Commands

We can use the SQL operator IN not only with the SELECT command , but also with other commands of the SQLite library . We why does my number show up as scam will not talk about transaction control operators and data access definition commands , since inside the first one you can write any SQL statements, but aol email list the second ones are not in SQLite.

SQLite data manipulation commands and the IN operator:

  1. We can create tables based on SELECT subquery, hence we can use IN operator.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top