Lets say I have a table with columns A , B , C , D and I want to do a match on column A and C
I see that you can either match a single column or all column in sqlite ie
- match column A
select * from table where A match 'cat'
- match all columns
select * from table where table match 'cat'
Is it possible to match only columns A and C? If not, how do you guys get around this?
Thanks for your suggestion!
To select multiple columns from a table, simply separate the column names with commas!
How do I UPDATE multiple columns in SQLite? First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause.
How do I add multiple columns in SQLite? SQLite does not support adding multiple columns to a table using a single statement. To add multiple columns to a table, you must execute multiple ALTER TABLE ADD COLUMN statements.
Connect to a database using the connect() method. Create a cursor object and use that cursor object created to execute queries in order to create a table and insert values into it. Use the description keyword of the cursor object to get the column names.
Instead of specifying which columns to match to, you can specify the entire table to match to. For example:
-- Example schema
CREATE VIRTUAL TABLE mail USING fts3(subject, body);
-- Example table population
INSERT INTO mail(docid, subject, body) VALUES(1, 'software feedback', 'found it too slow');
INSERT INTO mail(docid, subject, body) VALUES(2, 'software feedback', 'no feedback');
INSERT INTO mail(docid, subject, body) VALUES(3, 'slow lunch order', 'was a software problem');
-- Example queries
SELECT * FROM mail WHERE subject MATCH 'software'; -- Selects rows 1 and 2
SELECT * FROM mail WHERE body MATCH 'feedback'; -- Selects row 2
SELECT * FROM mail WHERE mail MATCH 'software'; -- Selects rows 1, 2 and 3
SELECT * FROM mail WHERE mail MATCH 'slow'; -- Selects rows 1 and 3
I don't think you can use multiple MATCH operators in a single FTS query. Use column_name:target_term to search multiple columns using one full text search.
SELECT * FROM table WHERE table MATCH 'A:cat OR C:cat'
http://www.sqlite.org/fts3.html#termprefix
For the multiple column condition using MATCH use UNION for the 'OR' and use INTERSECT for the 'AND'
SELECT * FROM TBL_VIRTUAL_APPOINTMENT WHERE PATIENT_PREFIX MATCH 'D*'
UNION
SELECT * FROM TBL_VIRTUAL_APPOINTMENT WHERE patient_first_name MATCH 'K*'
Using sub-queries as workaround:
OR
equivalent query, like a MATCH 'cat' OR c MATCH 'cat'
:
SELECT * FROM table
WHERE ROWID IN (
SELECT ROWID FROM table WHERE a MATCH 'cat'
UNION
SELECT ROWID FROM table WHERE b MATCH 'cat'
);
AND
equivalent query, like a MATCH 'cat' AND c MATCH 'cat'
:
SELECT * FROM table WHERE ROWID IN (
SELECT ROWID FROM table WHERE a MATCH 'cat'
AND ROWID IN (
SELECT ROWID FROM table WHERE b MATCH 'cat'
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With