The not greater than in a query can be written simply like less than or equal to ( <=). The syntax is as follows −
select * from yourTableName where yourColumnName<=yourColumnName;
Let us first create a table −
mysql> create table DemoTable1480 -> ( -> StudentName varchar(40), -> StudentMarks int -> ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1480 values('Chris',78); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1480 values('Bob',45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1480 values('John',67); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1480 values('Adam',56); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1480;
This will produce the following output −
+-------------+--------------+ | StudentName | StudentMarks | +-------------+--------------+ | Chris | 78 | | Bob | 45 | | John | 67 | | Adam | 56 | +-------------+--------------+ 4 rows in set (0.00 sec)
Following is the query to write not greater than in a MySQL query −
mysql> select * from DemoTable1480 where StudentMarks <=65;
This will produce the following output −
+-------------+--------------+ | StudentName | StudentMarks | +-------------+--------------+ | Bob | 45 | | Adam | 56 | +-------------+--------------+ 2 rows in set (0.00 sec)