ByteMe
ByteMe

Reputation: 1402

How to match row data against an array of values

Is there a good way to check for matches in a SQL column, using an array of data, without having to loop as shown? Assume the url array has 100+ links, the below is just an example.

url = ["www.site1.com", "www.site2.com"]
url.each do |url|
    match = db.execute("SELECT 1 FROM ListData WHERE Link=? ", url)
    if match[0][0] == 1
       flag = true
    end
end

Upvotes: 0

Views: 2289

Answers (1)

Dan Ionescu
Dan Ionescu

Reputation: 3423

Use WHERE IN clause like this:

SELECT 1 FROM ListData WHERE Link IN ('www.site1.com','www.site2.com')

Upvotes: 2

Related Questions