Given a table with the following columns
comment
minAge
maxAge
and the following rows:
comment, minAge, maxAge
"Baby", 1, 5
"Teen", 13, 19
"Adult", 20, 50
Is it possible to do a sql query like:
select * from rows where 16 between minAge and maxAge
With the results:
"Teen", 13, 19
The SQL BETWEEN condition allows you to easily test if an expression is within a range of values (inclusive). The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
Here's the generic SQL query to two compare columns (column1, column2) in a table (table1). mysql> select * from table1 where column1 not in (select column2 from table1); In the above query, update table1, column1 and column2 as per your requirement.
Answer. Yes, within a WHERE clause you can compare the values of two columns.
BETWEEN operator selects values within a range. The values can be numbers, text, or dates.
See your table and data yourself here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With