Počinjem sada malo ovime da se bavim.
Do sada sam radila samo neke male upite nad MySQL bazicama.
Dobar link za početnike (tj takve kao što sam ja).
Par opštih stvari vezanih za SQL :
SQL stands for Structured Query Language
SQL lets you access and manipulate databases
SQL is an ANSI (American National Standards Institute) standard
SQL keywords are NOT case sensitive
Some of The Most Important SQL Commands :
SELECT – extracts data from a database
UPDATE – updates data in a database
DELETE – deletes data from a database
INSERT INTO – inserts new data into a database
CREATE DATABASE – creates a new database
ALTER DATABASE – modifies a database
CREATE TABLE – creates a new table
ALTER TABLE – modifies a table
DROP TABLE – deletes a table
CREATE INDEX – creates an index (search key)
DROP INDEX – deletes an index
Uobičajena forma SQL upita :
SELECT column_name1,column_name2 FROM table_name;
SELECT DISTINCT column_name,column_name FROM table_name;
U ovom slučaju se traže sve JEDINSTVENE kombinacije OBE kolone, I to se prikazuje.
SELECT column_name,column_name FROM table_name WHERE column_name operator value;
Pri čemu se “WHERE” klauzula može odnositi na bilo koju vrednost iz navedenih kolona, npr :
select distinct Ime,Prezime,ImeOca from dbo.ZAPOSLENI where Ime=’VESNA’;
Operatori i njihov opis :
<> Not equal. Note: In some versions of SQL this operator may be written as !=
> Greater than
< Less than >= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
The AND operator displays a record if both the first condition AND the second condition are true.
The OR operator displays a record if either the first condition OR the second condition is true.
SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
Kako povezati dve tabele u istoj bazi, tako da jednim upitom prikazujemo podatke iz obe tabele :
Tabele su : Orders i Customers, a kolone Orders.CustomerID i Customers.CustomerID su iste u obe tabele (tj preko njih se ove tabele mogu povezati).
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
INNER JOIN Customers
SQL joins are used to combine rows from two or more tables.
% A substitute for zero or more characters – koristi se samo sa LIKE, ne sa =!!!!
_ A substitute for a single character – koristi se samo sa LIKE, ne sa =!!!!
[charlist] Sets and ranges of characters to match
[^charlist] or [!charlist] Matches only a character NOT specified within the brackets
Spajanje podataka iz tabela
An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.
The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN returns all rows from multiple tables where the join condition is met (link).
The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.
The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.
The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2).
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
Vizuelni prikaz (uzet odavde) :
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012