Skip to content

Instantly share code, notes, and snippets.

View ArCiGo's full-sized avatar
🎯
Learning

Armando Cifuentes ArCiGo

🎯
Learning
View GitHub Profile
SELECT "column_name1"[,
"column_name2"
...]
FROM "table_name";
GO
SELECT cus.FirstName,
cus.LastName
FROM Customer cus;
GO
/** Output **/
FirstName LastName
---------------------------------------- ----------------------------------------
Paolo Accorti
Pedro Afonso
SELECT "column_name"
FROM "table_name"
WHERE "condition";
UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";
DELETE FROM "table_name"
WHERE "condition";
SELECT *
FROM [ORDER] ord
WHERE ord.CustomerId = 85 AND ord.OrderDate = '20131112';
GO
/** Output **/
Id OrderDate OrderNumber CustomerId TotalAmount
----------- ----------------------- ----------- ----------- ---------------------------------------
492 2013-11-12 00:00:00.000 542869 85 240.00
SELECT *
FROM [ORDER] ord
WHERE ord.OrderDate = '20140101' OR ord.OrderDate = '20140130';
GO
/** Output **/
Id OrderDate OrderNumber CustomerId TotalAmount
----------- ----------------------- ----------- ----------- ---------------------------------------
561 2014-01-01 00:00:00.000 542938 55 1660.00
562 2014-01-01 00:00:00.000 542939 88 140.00
SELECT *
FROM [ORDER] ord
WHERE ord.CustomerId IN(85, 14, 1);
GO
/** Output **/
Id OrderDate OrderNumber CustomerId TotalAmount
----------- ----------------------- ----------- ----------- ---------------------------------------
1 2012-07-04 00:00:00.000 542378 85 440.00
7 2012-07-11 00:00:00.000 542384 14 625.20
SELECT *
FROM Customer cus
WHERE FirstName LIKE 'Maria';
GO
/** Output **/
Id FirstName LastName City Country Phone
----------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- --------------------
1 Maria Anders Berlin Germany 030-0074321
24 Maria Larsson Bräcke
SELECT *
FROM Customer cus
WHERE cus.FirstName LIKE 'A%'; --All names that starts with A
GO
/** Output **/
Id FirstName LastName City Country Phone
----------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- --------------------
2 Ana Trujillo México D.F. Mexico (5) 555-4729
3 Antonio Moreno México D.F. Mexico (5) 555-3932