I have two tables that I want to join and query. I want the query to return all records where the field columns value is between 2 values x, y. Table 1:
id int(11) YES NULL
game int(11) YES NULL
numbers varchar(255) YES NULL
bonus varchar(255) YES NULL
multiplier varchar(255) YES NULL
created int(11) YES NULL
data text YES NULL
Table 2:
bundle varchar(128) NO MUL
deleted tinyint(4) NO PRI 0
entity_id int(10) unsigned NO PRI NULL
revision_id int(10) unsigned NO MUL NULL
langcode varchar(32) NO PRI
delta int(10) unsigned NO PRI NULL
field_secondary_prize_value_value varchar(255) NO NULL
And the query :
SELECT
t1.id,
t2.field_secondary_prize_value_value
FROM
table1 t1
INNER JOIN table2 t2 ON
t1.id = t2.entity_id AND t2.field_secondary_prize_value_value BETWEEN 0 AND 10
ORDER BY
t2.field_secondary_prize_value_value
DESC;
The result sets should start with records where t2.field_secondary_prize_value_value
is 10
but this what I am getting:
ID. field_secondary_prize_value_value
1490476 5
1490496 5
1490531 5
1490596 5
1490636 5
1490651 5
1490666 5
1490676 5
1490756 5
1490761 5
If replace the between clause to equality: i.e:
INNER JOIN table2 t2 ON
t1.id = t2.entity_id AND t2.field_secondary_prize_value_value = 10
1490546 10
1490561 10
1490581 10
1490616 10
1490896 10
1491041 10
1491156 10
1491221 10
1491316 10
1491341 10
I tried casting varchar to int but I still got the same results.
If I order by a column on the base table I get results where field_secondary_prize_value_value
shows different values within the range.
Perhaps I need to use a subquery.