mysql

8
1 MySQL Salim Mail : [email protected] Phone : 0815-188-2384 YM : talim_bansal Blog : http://salimsribasuki.wordpress.com SQL for MySQL (I) 1 MySQL - Query

Upload: valiant

Post on 05-Jan-2016

33 views

Category:

Documents


0 download

DESCRIPTION

MySQL. SQL for MySQL (I). Salim Mail: [email protected] Phone: 0815-188-2384 YM: talim_bansal Blog: http://salimsribasuki.wordpress.com. 1. Summary. Retrieving Data Using the SQL SELECT Statement Restricting and Sorting Data Using Single-Row Functions to Customize Output. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: MySQL

1

MySQL

SalimMail : [email protected] : 0815-188-2384YM : talim_bansalBlog : http://salimsribasuki.wordpress.com

SQL for MySQL (I)

1MySQL - Query

Page 2: MySQL

Summary

•Retrieving Data Using the SQL SELECT Statement•Restricting and Sorting Data•Using Single-Row Functions to Customize Output

2MySQL - Query

Page 3: MySQL

SELECT COMMON PATTERN

SELECT <*, Field 1,….., Field n, Aggregate Function>FROM < Table Name>WHERE <Condition>AND/OR <If any additional condition>GROUP BY <Field 1,……, Field n>HAVING <Condition>ORDER BY <Field1,…., Field n>

3MySQL - Query

Page 4: MySQL

Retrieving Data Using the SQL SELECT Statement

•Select All ColumnsSyntax : SELECT * FROM <Table Name>;

Sample : SELECT * FROM ti3k_item_master

•Select Specific ColumnsSyntax : SELECT <Column Name, Column Name, Column Name,……Column Name>

FROM <Table Name>; Sample : SELECT item_id, item_name, item_uom FROM ti3k_item_master;

•Use Arithmetic Operators

4MySQL - Query

Page 5: MySQL

Retrieving Data Using the SQL SELECT Statement

•Understand Operator PrecedencePrecedence defines the order that Oracle uses when evaluating different operators in the same expression. Every operator has a predefined precedence. Oracle evaluates operators with a higher precedence before it evaluates operators with a lower precedence. Operators with equal precedence will be evaluated from left to right

5MySQL - Query

Page 6: MySQL

Restricting and Sorting Data

•Write queries that contain a WHERE clause to limit the output retrieved

Syntax : Select <Column Name,……Column Name> From <Table Name> Where <Column Name or Logical Phrase>;

Sample : SELECT item_id, item_name, item_uom FROM ti3k_item_master Where item_uom ='Set';

•Write queries that contain an ORDER BY clause sort the output of a SELECT statement (Ascending or Descending)

Sample : Select * from ti3k_item_master Order by item_uom asc;

Sample : Select * from ti3k_item_master Order by item_id desc;

6MySQL - Query

Page 7: MySQL

Restricting and Sorting Data

List the comparison operators and logical operators that are used in a WHERE clause

7MySQL - Query

Page 8: MySQL

Sample SELECT with WHERE using Comparison operators

Exercise:

select item_uom “UOM” from ti3k_item_masterwhere item_code =‘DRL10’;

select item_id, item_code, item_name, item_uom, remarkFrom ti3k_item_masterwhere item_id > 50And item_uom =‘Each’;

select * from ti3k_item_masterwhere item_uom in (‘Sax’,’Set’)Order by item_uom, item_id;

select * from ti3k_item_masterwhere remark is nullOr created_by = ‘Salim’;

select * from ti3k_item_masterwhere item_id between 10 and 20;

8MySQL - Query