Greater than the result of subquery : Sub query « Select Clause « SQL / MySQL






Greater than the result of subquery

       
mysql>
mysql>
mysql> CREATE   TABLE PENALTIES
    ->         (PAYMENTNO      INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          PAYMENT_DATE   DATE         NOT NULL,
    ->          AMOUNT         DECIMAL(7,2) NOT NULL,
    ->          PRIMARY KEY    (PAYMENTNO)          );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (6,  8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT   PAYMENTNO
    -> FROM     PENALTIES
    -> WHERE    AMOUNT >
    ->         (SELECT   AMOUNT
    ->          FROM     PENALTIES
    ->          WHERE    PAYMENTNO = 4);
+-----------+
| PAYMENTNO |
+-----------+
|         1 |
|         2 |
|         3 |
|         8 |
+-----------+
4 rows in set (0.00 sec)

mysql>
mysql> drop table PENALTIES;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Subqueries As Calculated Columns: Simple Subqueries
2.Subqueries in the WHERE Clause 2
3.Subqueries That Return Multiple Results
4.Sub queries
5.Sub query with string concatenate
6.Sub query with not equal and order
7.Sub query with calculation
8.Update command with sub query
9.Delete command with sub query
10.SubSELECTs Syntax Variants
11.Uses a subquery to return an AuthID value
12.Use a not equal (<>) comparison operator in the WHERE clause to introduce the subquery
13.Subquery uses an aggregate function to arrive at a value that the outer statement can use
14.Nested subquery
15.Four-level nested subquery with alias
16.Nested subquery and where clause
17.Minus value from subquery
18.Subquery and equals operator(ERROR 1242 (21000): Subquery returns more than 1 row)
19.Row values and subquery
20.Nested three level subquery
21.Equals to the result of subquery
22.Row values comparison for subquery
23.Select from the result of subquery
24.Value calculation of subquery
25.Subquery as a table
26.Alias subquery
27.Calculation in subquery
28.Using function with result from subquery
29.Create constant value in subquery
30.Calculation in subquery and use the result from outside
31.Equals operator with subquery
32.Less than and subquery(ERROR 1242 (21000): Subquery returns more than 1 row)
33.Less than data type value from subquery
34.<=> and subquery
35.Less than two values in subquery
36.Greater than two values in subquery
37.Get substring for a value from subquery
38.Mix constant value and subquery
39.Using the value from subquery with in operator
40.Pair value within in operator and subquery
41.In a list of value from subquery
42.In operator and subquery
43.Nested subquery and in operator
44.Not in and subquery
45.Between...and opertor and subquery
46.Count value in subquery
47.Add up count value from subquery
48.From a subquery
49.Aggregate function in subquery
50.Having clause with subquery
51.Count and subquery in Having clause
52.Subquery with having clause
53.Order by value from subquery
54.Subquery with limit clause
55.Insert statement with subquery
56.Use a derived table.
57.Searching for Titles Without Authors
58.Compare to aggregate function
59.Data calculation inside in operator
60.COMPARISON OPERATORS WITH SUBQUERIES
61.Select from three subqueries
62.Select from two subqueries
63.Row value comparison with select statement
64.Compare two data type value together
65.Nested subqueries
66.Two USING clauses, rather than ON clauses
67.Finding people who didn't send mail to themselves