Reputation: 359
I am working on a large database that contains wine names, prices, etc... I want to query a table for all chardonnay that is $10 or less per bottle, but I keep getting results that are $10.
dbGetQuery(db, "SELECT Name, Price FROM Wines
WHERE price<=10
AND name LIKE '%Chardonnay%'")
If I query only for Chardonnay I can see there are some under $10
895 Chardonnay 12
896 Reserve Chardonnay 16
897 Chardonnay 10
898 Wyckoff Vyd Chardonnay 21
899 Reserve Chardonnay 29
900 Fume Chardonnay 9
901 Barrel Fermented Chardonnay 13
902 Reserve Chardonnay 11
903 Chardonnay 10
904 Woodburne Cuvée Chardonnay 14
905 Chardonnay 7
When I run the above query I get this:
50 Chardonnay 10
51 Chardonnay 10
52 Chardonnay 10
53 Chardonnay 10
54 Chardonnay 10
55 Chardonnay 10
All 55 results had 10 as the price
I feel like it has to be a formatting issue, but I haven't been able to get it right
Upvotes: 1
Views: 265
Reputation: 2641
SQlite uses dynamic typing and you can insert strings into int columns. Likely your prices are inserted as strings or your price columns is not a number (integer, float) column. Make sure the column is of the right type and your prices values are inserted as the right type.
Upvotes: 2