-
part 2(this post)
- Get data from table and WHERE-clause
- JOIN TABLE part 3
- ALIASES
- USE of DISTINCT
- NULLS IN SQL QUERIES
- EXPLICIT SETS
- GROUP BY
- HAVING part 4
- ORDER BY
- AGGREGATE FUNCTIONS
- ARITHMETIC OPERATIONS
- SUBSTRING COMPARISON
- NESTING OF QUERIES
- THE EXISTS FUNCTION
- SET OPERATION (UNION)
I have shown the query and the table which is result of the query
Get data from table and WHERE-clause
SELECT * FROM powerplant.turbine;#UNSPECIFIED WHERE-clause
+----+--------------+---------+-----------+--------+ | id | manufacturer | details | genarator | weight | +----+--------------+---------+-----------+--------+ | 1 | man1 | yes | 1 | 10 | | 2 | man2 | no | 1 | 20 | | 3 | man3 | no | 2 | 50 | | 4 | man2 | no | 2 | 20 | | 5 | man2 | yes | 1 | NULL | +----+--------------+---------+-----------+--------+
SELECT * FROM `powerplant`.`turbine` WHERE `id` = 1;
+----+--------------+---------+-----------+--------+ | id | manufacturer | details | genarator | weight | +----+--------------+---------+-----------+--------+ | 1 | man1 | yes | 1 | 10 | +----+--------------+---------+-----------+--------+
SELECT * FROM `powerplant`.`turbine` WHERE NOT `id` = 1;
+----+--------------+---------+-----------+--------+ | id | manufacturer | details | genarator | weight | +----+--------------+---------+-----------+--------+ | 1 | man1 | yes | 1 | 10 | +----+--------------+---------+-----------+--------+
SELECT `manufacturer`,`details` FROM `powerplant`.`turbine` WHERE `details` = 'yes' AND `manufacturer`='man1';
+--------------+---------+ | manufacturer | details | +--------------+---------+ | man1 | yes | +--------------+---------+
SELECT `manufacturer`,`details` FROM `powerplant`.`turbine` WHERE `details` = 'no' OR `manufacturer`='man1';
+--------------+---------+ | manufacturer | details | +--------------+---------+ | man1 | yes | | man2 | no | | man3 | no | | man2 | no | +--------------+---------+
JOIN TABLE
SELECT * FROM genarator,turbine;
+----+-------------+----+--------------+---------+-----------+--------+ | id | outputpower | id | manufacturer | details | genarator | weight | +----+-------------+----+--------------+---------+-----------+--------+ | 1 | 10 | 1 | man1 | yes | 1 | 10 | | 2 | 20 | 1 | man1 | yes | 1 | 10 | | 1 | 10 | 2 | man2 | no | 1 | 20 | | 2 | 20 | 2 | man2 | no | 1 | 20 | | 1 | 10 | 3 | man3 | no | 2 | 50 | | 2 | 20 | 3 | man3 | no | 2 | 50 | | 1 | 10 | 4 | man2 | no | 2 | 20 | | 2 | 20 | 4 | man2 | no | 2 | 20 | | 1 | 10 | 5 | man2 | yes | 1 | NULL | | 2 | 20 | 5 | man2 | yes | 1 | NULL | +----+-------------+----+--------------+---------+-----------+--------+
SELECT * FROM genarator INNER JOIN turbine;
+----+-------------+----+--------------+---------+-----------+--------+ | id | outputpower | id | manufacturer | details | genarator | weight | +----+-------------+----+--------------+---------+-----------+--------+ | 1 | 10 | 1 | man1 | yes | 1 | 10 | | 2 | 20 | 1 | man1 | yes | 1 | 10 | | 1 | 10 | 2 | man2 | no | 1 | 20 | | 2 | 20 | 2 | man2 | no | 1 | 20 | | 1 | 10 | 3 | man3 | no | 2 | 50 | | 2 | 20 | 3 | man3 | no | 2 | 50 | | 1 | 10 | 4 | man2 | no | 2 | 20 | | 2 | 20 | 4 | man2 | no | 2 | 20 | | 1 | 10 | 5 | man2 | yes | 1 | NULL | | 2 | 20 | 5 | man2 | yes | 1 | NULL | +----+-------------+----+--------------+---------+-----------+--------+
SELECT * FROM genarator,turbine WHERE genarator.id=turbine.genarator;
+----+-------------+----+--------------+---------+-----------+--------+ | id | outputpower | id | manufacturer | details | genarator | weight | +----+-------------+----+--------------+---------+-----------+--------+ | 1 | 10 | 1 | man1 | yes | 1 | 10 | | 1 | 10 | 2 | man2 | no | 1 | 20 | | 2 | 20 | 3 | man3 | no | 2 | 50 | | 2 | 20 | 4 | man2 | no | 2 | 20 | | 1 | 10 | 5 | man2 | yes | 1 | NULL | +----+-------------+----+--------------+---------+-----------+--------+
SELECT * FROM genarator INNER JOIN turbine ON genarator.id=turbine.genarator;
+----+-------------+----+--------------+---------+-----------+--------+ | id | outputpower | id | manufacturer | details | genarator | weight | +----+-------------+----+--------------+---------+-----------+--------+ | 1 | 10 | 1 | man1 | yes | 1 | 10 | | 1 | 10 | 2 | man2 | no | 1 | 20 | | 2 | 20 | 3 | man3 | no | 2 | 50 | | 2 | 20 | 4 | man2 | no | 2 | 20 | | 1 | 10 | 5 | man2 | yes | 1 | NULL | +----+-------------+----+--------------+---------+-----------+--------+
Great work.keep it up
ReplyDeleteGreat help for beginners. Well done 👍
ReplyDeleteVery helpful. Thank you.
ReplyDelete