topbennie
topbennie

Reputation: 149

How to check if one column value is greater than another in mysql

I would like to get results where value in one column is greater than values in another.

Example

select * FROM myTable where column time_taken is greater than time_spent

Thanks for the help.

Upvotes: 1

Views: 11035

Answers (3)

Greg Sansom
Greg Sansom

Reputation: 20840

select * FROM myTable where time_taken > time_spent

To see a list of other operators available in MySql, have a look at http://dev.mysql.com/doc/refman/5.0/en/non-typed-operators.html

Upvotes: 3

Matt Sieker
Matt Sieker

Reputation: 9635

select * from myTable where time_taken > time_spent

Figuring out less than, less than equal to, greater than or equal to is left as an exercise to the reader.

Upvotes: 1

ajreal
ajreal

Reputation: 47321

depend of the column type, both column are in the same data type, it can be done via

time_taken > time_spent

otherwise, some casting might required, like

cast(time_taken as signed) > time_spent

see casting

Upvotes: 2

Related Questions