1

I'm trying to create an address book and I'd need to check if a given input can be found in all of three columns of the table i created:

conn = sqlite3.connect("Address_Book.db")
c = conn.cursor()

c.execute("""CREATE TABLE addresses (
        name text,
        number text,
        email text)
    """)

    conn.commit()

c.execute("SELECT rowid, * FROM addresses WHERE name LIKE (?)", ('%' + self + '%',))          
res = c.fetchall()

In the above code I'm only searching the 'name' column. I tried writing 'name, number, email' but maybe I don't know the correct syntax and couldn't find it online. I found a way around the problem but it's not that elegant, so I hope someone can help, thank you in advance.

1
  • 1
    Did you try concatenation name||number||email ? Commented Nov 3, 2020 at 18:46

1 Answer 1

2

A simple workaround for your SQL query would be using the OR operator. As an example, please have a look at the following query

SELECT * from addresses where name LIKE '%A%'
OR number LIKE '%A%'
OR email LIKE '%A%'
Sign up to request clarification or add additional context in comments.

1 Comment

@Grinch Glad to hear that. Can you please accept my solution as correct, if it works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.