SELECT * FROM table WHERE col1 <= col2?
I want to select rows from a table where the value of column_x
is less than column_y
. This is what I've got:
$query = "SELECT *
FROM table_name
WHERE timestamp <= '$timestamp'
AND hit_counter <= max_hits";
Does anyone have any idea if this will w开发者_Go百科ork, and if not what I could do to get this kind of functionality :).
It works perfectly. Here's a test case in SQL Server but it's the same in MySQL:
create table #test
(
a int,
b int
)
insert into #test
values (1,2),(2,2),(5,4),(5,2)
select a,b from #test
a b
1 2
2 2
5 4
5 2
select a,b from #test where a<=b
a b
1 2
2 2
Looks proper but I would try to remove the timestamp <= '$timestamp' portion first and re-execute. That's the only part I can see issues coming up. $timestamp could perhaps be the wrong format and/or the '' will render the value incorrectly a string.
精彩评论