Mysql Difference
Mysql Difference is used to return the records that are the outcome of difference between the records in a table.
Understand with Example
The Tutorial illustrate an example from 'Mysql Difference'.To understand this example we create a table 'Multiplication'.The table 'Multiplication' is created with required field name and datatype respectively.
Query for creating table name Multiplication:
mysql> CREATE TABLE Multiplication( -> a int(10), -> b int(19), -> c int(21) -> ); Query OK, 0 rows affected (0.03 sec) |
Query for Multiple insertion of data in table:
The Query insert into for inserting a multiple records or rows to the table 'Multiplication'.
mysql> insert into Multiplication (a,b,c)values -> (12,13,15), -> (22,23,25), -> (32,33,35), -> (42,43,45), -> (52,53,55), -> (62,65,64 Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0 |
Query to view data inserted in table:
To view the records we use select query that returns you table details.
mysql> select * from multiplication; |
Output:-
mysql> select * from multiplication; +------+------+------+ | a | b | c | +------+------+------+ | 12 | 13 | 15 | | 22 | 23 | 25 | | 32 | 33 | 35 | | 42 | 43 | 45 | | 52 | 53 | 55 | | 62 | 65 | 64 | +------+------+------+ 6 rows in set (0.00 sec) |
Query to view Mysql difference of data inserted in table:
The below Query in Mysql is used to view difference of data inserted in a table 'Multiplication'.
mysql> select *,a-b from multiplication ; |
Output:-
+------+------+------+------+ | a | b | c | a-b | +------+------+------+------+ | 12 | 13 | 15 | -1 | | 22 | 23 | 25 | -1 | | 32 | 33 | 35 | -1 | | 42 | 43 | 45 | -1 | | 52 | 53 | 55 | -1 | | 62 | 65 | 64 | -3 | +------+------+------+------+ 6 rows in set (0.00 sec) |