10 Event Queries Of Sql Guide Command

10 Event Queries Of Sql Guide Command - Hallo sahabat BEST LEARNING JAVA, Pada Artikel yang anda baca kali ini dengan judul 10 Event Queries Of Sql Guide Command, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan Artikel database, Artikel mysql, Artikel SQL, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : 10 Event Queries Of Sql Guide Command
link : 10 Event Queries Of Sql Guide Command

Baca juga


10 Event Queries Of Sql Guide Command

The Select ascendence inward SQL is i of the most powerful in addition to heavily used commands. This is I guess the showtime ascendence anyone larn inward SQL fifty-fifty earlier CREATE which is used to create a tabular array inward SQL. SELECT is used inward SQL to fetch records from database tables in addition to you lot tin do a lot many things using Select. For example, you lot tin select all records, you lot tin select few records based on the status specified inward WHERE clause, select all columns using the wild bill of fare (*) or alone selecting a few columns past times explicitly declaring them inward a query.

In this SELECT SQL ascendence tutorial, nosotros volition run into to a greater extent than or less examples of select command or Select Statement in addition to volition write SQL queries to demonstrate the result. We volition work next tabular array in addition to information for our SQL question examples, i tabular array stand upwards for Stocks listed inward diverse marketplace position in addition to to a greater extent than or less other tabular array contains Details of marketplace position e.g. Country. MySQL is my favorite RDBMS in addition to keen for learning work you lot tin download MySQL in addition to start working on it. My proposition is to work ascendence occupation interface for writing queries instead of using GUI e.g. SQL Developer or MySQL question tool. Command occupation is best for learning in addition to existent fun of writing SQL question is alone on the ascendence prompt.


mysql> select * from STOCK;
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| 6758.T  | Sony                    | T                  |
| GOOG.O  | Google Inc              | O                  |
| GS.N    | Goldman Sachs Group Inc | N                  |
| INFY.BO | InfoSys                 | BO                 |
| VOD.L   | Vodafone Group PLC      | L                  |
+---------+-------------------------+--------------------+
5 rows inward ready (0.00 sec)

mysql> select * from MARKET;
+------+-------------------------+---------------+
| RIC  | NAME                    | COUNTRY       |
+------+-------------------------+---------------+
| T    | Tokyo Stock Exchange    | Japan         |
| O    | NASDAQ                  | U.S.A. |
| N    | New York Stock Exchange | U.S.A. |
| BO   | Mumbai Stock Exchange   | India         |
+------+-------------------------+---------------+
4 rows inward ready (0.00 sec)



SQL SELECT ascendence question examples

hither are to a greater extent than or less of my favorite select clause examples which explore unlike ways i tin work the select ascendence for reporting work in addition to display results.
1) Finding how many rows inward tables

mysql> select count(*) from STOCK;
+----------+
| count(*) |
+----------+
|        five |
+----------+
 is i of the most powerful in addition to heavily used commands 10 Example Queries of SQL Select Command

2) Finding all records from tables; nosotros are using wildcard start * for getting all columns.

mysql> select * from STOCK;
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| 6758.T  | Sony                    | T                  |
| GOOG.O  | Google Inc              | O                  |
| GS.N    | Goldman Sachs Group Inc | N                  |
| INFY.BO | InfoSys                 | BO                 |
| VOD.L   | Vodafone Group PLC      | L                  |
+---------+-------------------------+--------------------+
5 rows inward ready (0.00 sec)


3. Selecting few records based on to a greater extent than or less status from tables inward SQL

mysql> select * from STOCK where RIC='GOOG.O';
+--------+------------+--------------------+
| RIC    | COMPANY    | LISTED_ON_EXCHANGE |
+--------+------------+--------------------+
| GOOG.O | Google Inc | O                  |
+--------+------------+--------------------+


4. How to select few columns instead of all columns?
Instead of using start wild-card only attain the advert of interested columns to SELECT clause.

mysql> select COMPANY from STOCK where RIC='GOOG.O';
+------------+
| COMPANY    |
+------------+
| Google Inc |
+------------+

5. Select distinct (unique) records from Columns
The distinct keyword is used to exhibit alone unique records it volition non exhibit whatsoever duplicate values.

mysql> select distinct LISTED_ON_EXCHANGE from Stock;
+--------------------+
| LISTED_ON_EXCHANGE |
+--------------------+
| T                  |
| O                  |
| N                  |
| BO                 |
| L                  |
+--------------------+


6. Selecting value with status based on less than, greater than (>, <, >=, <=) etc.

mysql> select * from Stock where RIC > 'I';
+---------+--------------------+--------------------+
| RIC     | COMPANY            | LISTED_ON_EXCHANGE |
+---------+--------------------+--------------------+
| INFY.BO | InfoSys            | BO                 |
| VOD.L   | Vodafone Group PLC | L                  |
+---------+--------------------+--------------------+

7. Combining status using logical operator AND & OR
AND in addition to OR Can endure effectively used to combine 2 weather condition on WHERE clause in addition to gives you lot a lot of flexibility to write SQL query.

mysql> select * from Stock where RIC <'I' AND RIC > 'G';
+--------+-------------------------+--------------------+
| RIC    | COMPANY                 | LISTED_ON_EXCHANGE |
+--------+-------------------------+--------------------+
| GOOG.O | Google Inc              | O                  |
| GS.N   | Goldman Sachs Group Inc | N                  |
+--------+-------------------------+--------------------+

You tin pose whatsoever publish of AND, OR weather condition on WHERE Clause, sometimes things conk quite slow when you lot combine AND, OR inward SQL.


8. How to abide by records which are non zero using keyword NULL in addition to IS NULL
NULL is rattling tricky inward SQL; NULL agency anything which doesn't create got value. NULL is non "null" which volition endure treated every bit text.To demonstrate this nosotros volition insert a Stock which is non listed on whatsoever Market yet.

mysql> select * from STOCK;
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| 6758.T  | Sony                    | T                  |
| GOOG.O  | Google Inc              | O                  |
| GS.N    | Goldman Sachs Group Inc | N                  |
| INDIGO  | INDIGO Airlines         | NULL               |
| INFY.BO | InfoSys                 | BO                 |
| VOD.L   | Vodafone Group PLC      | L                  |
+---------+-------------------------+--------------------+
6 rows inward ready (0.00 sec)

You See in that location is alone i row who has LISTED_ON_EXCHANGE null, nosotros volition directly run into count using NULL in addition to IS NULL which volition verify this result.

mysql> select count(*) from STOCK where LISTED_ON_EXCHANGE IS NULL;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row inward ready (0.00 sec)

mysql> select count(*) from STOCK where LISTED_ON_EXCHANGE IS NOT NULL;
+----------+
| count(*) |
+----------+
|        five |
+----------+
1 row inward ready (0.00 sec)

mysql> select count(*) from STOCK;
+----------+
| count(*) |
+----------+
|        half-dozen |
+----------+
1 row inward ready (0.00 sec)


9. SELECT Statement using BETWEEN in addition to NOT BETWEEN

As the advert propose BETWEEN is used to acquire information betwixt ranges.

mysql> select * from Stock where RIC BETWEEN 'G' AND 'I';
+--------+-------------------------+--------------------+
| RIC    | COMPANY                 | LISTED_ON_EXCHANGE |
+--------+-------------------------+--------------------+
| GOOG.O | Google Inc              | O                  |
| GS.N   | Goldman Sachs Group Inc | N                  |
+--------+-------------------------+--------------------+


10. Pattern matching inward SQL queries using LIKE in addition to NOT LIKE
LIKE is a designing matching operator in addition to used to abide by records which are non an exact gibe but in all likelihood match.

mysql> select * from Stock where RIC LIKE 'V%';
+-------+--------------------+--------------------+
| RIC   | COMPANY            | LISTED_ON_EXCHANGE |
+-------+--------------------+--------------------+
| VOD.L | Vodafone Group PLC | L                  |
+-------+--------------------+--------------------+

NOT LIKE is opposit of LIKE in addition to display records which are non in all likelihood match.
mysql> select * from Stock where RIC NOT LIKE 'V%';
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| 6758.T  | Sony                    | T                  |
| GOOG.O  | Google Inc              | O                  |
| GS.N    | Goldman Sachs Group Inc | N                  |
| INDIGO  | INDIGO Airlines         | NULL               |
| INFY.BO | InfoSys                 | BO                 |
+---------+-------------------------+--------------------+

11. IN in addition to NOT IN
IN is to a greater extent than or less other useful SQL operator nosotros tin work amongst SELECT. it provides a ready of values which tin endure used inward WHERE clause.

mysql> select * from Stock where RIC inward ('GS.N' , 'INFY.BO');
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| GS.N    | Goldman Sachs Group Inc | N                  |
| INFY.BO | InfoSys                 | BO                 |
+---------+-------------------------+--------------------+


12. Sorting ResultSet inward SQL using ORDER BY, ASC, DESC
Order past times is used to form records inward the final result ready returned past times SELECT clause. By default, it listing inward Ascending guild but nosotros tin work either ascending or descending using specifier ASC in addition to DESC.

mysql> select * from Stock guild past times COMPANY;
+---------+-------------------------+--------------------+
| RIC     | COMPANY                 | LISTED_ON_EXCHANGE |
+---------+-------------------------+--------------------+
| GS.N    | Goldman Sachs Group Inc | N                  |
| GOOG.O  | Google Inc              | O                  |
| INDIGO  | INDIGO Airlines         | NULL               |
| INFY.BO | InfoSys                 | BO                 |
| 6758.T  | Sony                    | T                  |
| VOD.L   | Vodafone Group PLC      | L                  |
+---------+-------------------------+--------------------+


14. Selecting information from multiple tables past times using JOIN inward SQL
Join inward SQL is a powerful concept which allows you lot to select information from multiple tables. You tin generate a study where information is accumulated from unlike tables based on weather condition specified inward Join statement.

Suppose you lot take away to “display a listing of Records in addition to Name of Market where they are listed”. Here the advert of Stock inward the STOCK tabular array piece the advert of telephone commutation inward the MARKET table. We take away to bring together both of them to display this report.

mysql> select s.RIC, m.NAME from Stock s, Market 1000 where s.LISTED_ON_EXCHANGE=m.RIC;
+---------+-------------------------+
| RIC     | NAME                    |
+---------+-------------------------+
| 6758.T  | Tokyo Stock Exchange    |
| GOOG.O  | NASDAQ                  |
| GS.N    | New York Stock Exchange |
| INFY.BO | Mumbai Stock Exchange   |
+---------+-------------------------+

Above method is called implicit Join an d This question tin also endure written past times using explicit bring together way which uses ON clause to bring together tables.

mysql> select s.RIC, m.NAME from Stock s INNER JOIN  Market ON 1000 I s.LISTED_ON_EXCHANGE=m.RIC;



15. Calling business office on SELECT clause e.g. displaying electrical flow date

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2011-10-13 10:25:47 |
+---------------------+

16. Doing calculation using SELECT CLAUSE
You tin perform to a greater extent than or less basic calculation using SELECT clause e.g addition, subtraction, multiplication, partitioning etc.

mysql> select 1+2;
+-----+
| 1+2 |
+-----+
|   three |
+-----+


17. SELECT information from i row till to a greater extent than or less other row similar Paging
If you lot are thinking to implement paging in addition to getting information from specified row you lot tin do this easily inward Mysql past times using LIMIT clause.

mysql> select * from Stock guild past times COMPANY LIMIT 0,2;
+--------+-------------------------+--------------------+
| RIC    | COMPANY                 | LISTED_ON_EXCHANGE |
+--------+-------------------------+--------------------+
| GS.N   | Goldman Sachs Group Inc | N                  |
| GOOG.O | Google Inc              | O                  |
+--------+-------------------------+--------------------+

Here showtime parameter '0' says start from the showtime tape in addition to '2' says to acquire 2 records only.

18. Selecting information from the final result of to a greater extent than or less other question past times using derived table.
Sometimes information needed to make concluding SELECT final result comes from to a greater extent than or less other question in addition to human activity every bit a tabular array for the outer SELECT statement. This tabular array also called Derived table

mysql> select RIC from (select s.RIC, m.NAME from Stock s, Market 1000 where s.LISTED_ON_EXCHANGE=m.RIC) t where RIC > 'G'

+---------+
| RIC     |
+---------+
| GOOG.O  |
| GS.N    |
| INFY.BO |
+---------+


Some Important betoken close SELECT ascendence inward SQL:


So Far nosotros create got seen unlike examples of a SELECT clause inward SQL which volition enable you lot to accept amount wages of SELECT piece writing SQL queries. Here I create got listed to a greater extent than or less of import points which you lot should consider piece writing SQL question non only SELECT but with whatsoever other keyword also.

1) Most oftentimes nosotros work SELECT Operator with WHERE Clause, endeavour to work column which has the index on WHERE clause. Using a non-index column on WHERE clause tin boring your question drastically in addition to upshot would endure to a greater extent than visible when your tabular array information increases. an illustration with 1 Million records question without index was taking 80-second piece later on index it only took .3 second, whopping 260% increment inward speed.

2) If you lot don't take away all columns, don’t work the * wild card. SELECT question with few columns is slightly faster than all columns.

3) If you lot are retrieving information from a large table, do a count (*) banking concern check earlier firing actual select query, this volition attain you lot en approximate of how many records you lot are close to acquire in addition to how much fourth dimension it could take.

4) You can innovate novel columns inward the final result ready of SELECT Query past times using keyword "AS" as shown inward below example. Very useful for displaying calculated value e.g. average or percentage.

5) Always use IS NULL or NULL for including or excluding values which could endure null. Don’t work 'null' that volition endure treated every bit text.

6) While writing SQL query, non only SELECT, its practiced practise to write a keyword inward the modest instance and TABLES in addition to COLUMNS inward capital. So that they volition stand upwards out from the whole question in addition to makes the question to a greater extent than readable.

That's all on SQL Select ascendence examples, I tried to embrace a practiced publish of select ascendence illustration to render an overview what SELECT contention tin do. If you lot know whatsoever practiced select illustration inward SQL delight share.

Further Learning
Difference betwixt truncate in addition to delete inward SQL


Demikianlah Artikel 10 Event Queries Of Sql Guide Command

Sekianlah artikel 10 Event Queries Of Sql Guide Command kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel 10 Event Queries Of Sql Guide Command dengan alamat link https://bestlearningjava.blogspot.com/2019/09/10-event-queries-of-sql-guide-command.html

Belum ada Komentar untuk "10 Event Queries Of Sql Guide Command"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel