And
Take the logical AND of the values in registers P1 and P2 and write the result into register P3.
An example
1 of the 178 statements we compiled against the sample database use And. This is the one with the shortest program; the rows that use And are highlighted.
SELECT (id > 5) AND (ms > 1000), (id > 5) OR (ms > 1000) FROM tracks
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 24 | 0 | 0 | |
| 1 | OpenRead | 0 | 4 | 0 | 4 | 0 |
| 2 | Rewind | 0 | 23 | 0 | 0 | |
| 3 | Rowid | 0 | 3 | 0 | 0 | |
| 4 | Integer | 1 | 1 | 0 | 0 | |
| 5 | Gt | 4 | 7 | 3 | 68 | |
| 6 | ZeroOrNull | 3 | 1 | 4 | 0 | |
| 7 | Column | 0 | 3 | 5 | 0 | |
| 8 | Integer | 1 | 3 | 0 | 0 | |
| 9 | Gt | 6 | 11 | 5 | BINARY-8 | 68 |
| 10 | ZeroOrNull | 5 | 3 | 6 | 0 | |
| 11 | And | 3 | 1 | 1 | 0 | |
| 12 | Rowid | 0 | 3 | 0 | 0 | |
| 13 | Integer | 1 | 2 | 0 | 0 | |
| 14 | Gt | 4 | 16 | 3 | 68 | |
| 15 | ZeroOrNull | 3 | 2 | 4 | 0 | |
| 16 | Column | 0 | 3 | 5 | 0 | |
| 17 | Integer | 1 | 3 | 0 | 0 | |
| 18 | Gt | 6 | 20 | 5 | BINARY-8 | 68 |
| 19 | ZeroOrNull | 5 | 3 | 6 | 0 | |
| 20 | Or | 3 | 2 | 2 | 0 | |
| 21 | ResultRow | 1 | 2 | 0 | 0 | |
| 22 | Next | 0 | 3 | 0 | 1 | |
| 23 | Halt | 0 | 0 | 0 | 0 | |
| 24 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 25 | Integer | 5 | 4 | 0 | 0 | |
| 26 | Integer | 1000 | 6 | 0 | 0 | |
| 27 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, Goto, Gt, Halt, Init, Integer, Next, OpenRead, Or, ResultRow, Rewind, Rowid, Transaction, ZeroOrNull.
What the SQLite documentation says
Take the logical AND of the values in registers P1 and P2 and write the result into register P3.
If either P1 or P2 is 0 (false) then the result is 0 even if the other input is NULL. A NULL and true or two NULLs give a NULL output.
From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.
← AggValue · AutoCommit →