MYSQL Ver.02 (SELECT, WHERE)
MYSQL -SQL
SQL은 'Structured Query Language'의 약자로, 데이터베이스에서 데이터를 추출하고 조작하는 데에 사용하는 데이터 처리 언어입니다. 쉽게 말해 데이터베이스에 저장된 정보를 쉽게 찾고 정리하는 데에 도움을 주는 도구입니다.
What is SQL?
SQL is the standard language for dealing with Relational Databases.
SQL is used to insert, search, update, and delete database records.
How to Use SQL
The following SQL statement selects all the records in the "Customers" table:
SELECT * FROM Customers;
SELECT(선택해라) / * (모든 것을) / customers (customers에 있는) .
The MySQL SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax
SELECT
column1, column2, ...
FROM
table_name;
column1, column2, ... are the field names of the table you want to select data from.
SELECT (선택해라)
column1, column2 (테이블의 필드네임을)
FROM
table_name
(table_name에 있는)
SELECT Columns
selects the "CustomerName", "City", and "Country" columns from the "Customers" table
SELECT (선택해라)
CustomerName, City, Country (테이블의 필드 네임(Column) 이 customer name, city, country 들을)
FROM
Customers
(테이블 name customers 인 테이블로 부터 )
The MySQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
Distinct
뚜렷한, 분명한, 뚜렷이 다른[구별되는], 별개의
테이블 안에 > column에 > 복제됐거나 중복된 것들이 있을거여 그리고 너는 distinct values 를 원할 수 있자나? 그럴 때 써.
SELECT
(선택해라)
DISTINCT
(구별되는, 별개의)
column1, column2, ...
(컬럼1) or (column1과 column2 를)
FROM table_name;
(테이블에서)
SELECT DISTINCT Country FROM Customers;
SELECT Country FROM Customers;
위에 두개 다른건가!?
DISTINCT 를 쓰면 중복된 COUNTRY가 제거 된다.
Mexico
가 2개 들어있는데 전부 검색된다.
SELECT COUNT(DISTINCT Country) FROM Customers;
COUNT()
The COUNT() function returns the number of rows that matches a specified criterion.
자 그럼 COUNT() 괄호 안에 DISTINCT 를 빼고 COUNTRY 만 넣는다면 총 몇개 나올까?
The MySQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
SELECT는 statement 이고 WHERE는 Clause 이다.
SELECT 구문 WHERE 조건절 로 구분을 하고 자세한 내용은 검색해라. 도움된다.
대충 말하자면 구문은 절보다 더 큰 개념이다.
SELECT가 WHERE 보다 크므로 SELECT 구문 뒤에 WHERE 조건절을 추가하여 특정한 컬럼의 값을 조회할 수 있다.
테이블에 있는 특정한 컬럼의 값을 검색한다....
WHERE 조건절의 기본 문법
SELECT column1, column2, ... FROM table_name WHERE condition; |
SELECT (선택해라 장소를 ) column1, column2, ... (그런데 그 장소는 컬럼1과 컬럼2를) FROM table_name (테이블이름으로 부터) WHERE condition; (어떤 조건을 갖고 곳의 장소만) |
선택해라 강남과 강북을 서울특별시에서 근데 강남과 강북에 사는 20대 이상만 |
The WHERE clause is not only used in SELECT statements, it is also used in UPDATE, DELETE, etc.!
WHERE clause 는 SELECT 이외에도 UPDATE랑 DELETE 랑 같이 쓸 수도 있어요.
The following SQL statement selects all the customers from 'Mexico':
SELECT * FROM Customers
WHERE Country = 'Mexico';
Text Fields vs. Numeric Fields
SQL requires single quotes around text values (most database systems will also allow double quotes).
However, numeric fields should not be enclosed in quotes:
text values 는 '' 로 감싸 줘.
숫자는 안해도 돼.
SELECT * FROM Customers
WHERE CustomerID = 1;
위에 멕시코는 있고 여긴 없쥬.
Operators in The WHERE Clause
<> | Not equal. Note: In some versions of SQL this operator may be written as != | |
BETWEEN | Between a certain range | |
LIKE | Search for a pattern | |
IN | To specify multiple possible values for a column |