SQL UPDATE
เป็นคำสั่งที่ใช้สำหรับลบข้อมูลในตาราง (Table) โดยสามารถทำการลบได้หลาย Record ภายในคำสั่งเดียว หรือว่า Record เดียว ทั้งนี้ขึ้นอยู่กับ Where ที่ผูใช้เขียนขึ้นด้วย
Database : MySQL,Microsoft Access,SQL Server,Oracle
Syntax
DELETE FROM [Table-Name] WHERE clause
Table : country
CountryCode
|
CountryName
|
---|---|
TH
| Thailand |
EN
| English |
US
| United states |
JP
| Japan |
Sample1 การลบข้อมูลลงใน Table
DELETE FROM country WHERE CountryCode = 'JP'
Output
CountryCode
|
CountryName
|
---|---|
TH
| Thailand |
EN
| English |
US
| United states |
SQL TOP
เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) ที่สามารถกำหนดจำนวน Record ที่แสดงผลออกมาได้
Database : Microsoft Access,SQL Server
Syntax
SELECT TOP [Integer] Column1, Column2, Column3,... FROM [Table-Name] ORDER BY [Field] [ASC/DESC]
Table : customer
CustomerID
|
Name
|
Email
|
CountryCode
|
Budget
|
Used
|
---|---|---|---|---|---|
C001
| Win Weerachai | win.weerachai@thaicreate.com |
TH
| 1000000 | 600000 |
C002
| John Smith | john.smith@thaicreate.com |
EN
| 2000000 | 800000 |
C003
| Jame Born | jame.born@thaicreate.com |
US
| 3000000 | 600000 |
C004
| Chalee Angel | chalee.angel@thaicreate.com |
US
| 4000000 | 100000 |
Sample1 การเลือกข้อมูลที่จำนวน Budget มากที่สุดออกมา 2 Record
SELECT TOP 2 * FROM customer ORDER BY Budget DESC
Output
CustomerID
|
Name
|
Email
|
CountryCode
|
Budget
|
Used
|
---|---|---|---|---|---|
C004
| Chalee Angel | chalee.angel@thaicreate.com |
US
| 4000000 | 100000 |
C003
| Jame Born | jame.smith@thaicreate.com |
US
| 3000000 | 600000 |
SQL LIMIT
เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) ที่สามารถกำหนดจำนวน Record ที่แสดงผลออกมาได้
Database : MySQL
Syntax
SELECT Column1, Column2, Column3,... FROM [Table-Name] ORDER BY [Fields] [ASC/DESC] LIMIT [Int-Start] , [Int-End]
Table : customer
CustomerID
|
Name
|
Email
|
CountryCode
|
Budget
|
Used
|
---|---|---|---|---|---|
C001
| Win Weerachai | win.weerachai@thaicreate.com |
TH
| 1000000 | 600000 |
C002
| John Smith | john.smith@thaicreate.com |
EN
| 2000000 | 800000 |
C003
| Jame Born | jame.born@thaicreate.com |
US
| 3000000 | 600000 |
C004
| Chalee Angel | chalee.angel@thaicreate.com |
US
| 4000000 | 100000 |
Sample1 การเลือกข้อมูลที่มีการใช้ยอดเงินมากที่สุดจำนวน 2 Record
SELECT * FROM customer ORDER BY Used DESC LIMIT 0,2
Output
CustomerID
|
Name
|
Email
|
CountryCode
|
Budget
|
Used
|
---|---|---|---|---|---|
C002
| John Smith | john.smith@thaicreate.com |
EN
| 2000000 | 800000 |
C001
| Win Weerachai | win.weerachai@thaicreate.com |
TH
| 1000000 | 600000 |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น