SQL must know

Source: Internet
Author: User
Tags first row

1. Understanding SQL

The simplest way is to think of the database as a file cabinet . This file cabinet is a physical location for storing data .

When you put the information in the cabinet, you create the file in the cabinet and then put the relevant information in a specific file . This file is called a table .

  table: A structured list of data of a particular type .

  The data stored in the table is the same type of data or manifest .

  Schema: Information about the layout and characteristics of databases and tables .

  The table is made up of columns.

  column: A field in the table. All tables are made up of one or more columns .

  each column in the database has a corresponding data type .

  data type: The type of data that is allowed. Each table column has a corresponding data type that restricts (or allows) the data stored in that column .

  The data in the table is stored on a row, and each saved record is stored in its own row .

  row: A record in the table .

  Each row in the table should have a column (or columns) to uniquely identify itself.

primary KEY (primary key): A column (or set of columns) whose value uniquely identifies each row in the table .

2. Retrieving data

1) retrieving a single column

  using Select to retrieve table data, you must give at least two messages---what you want to choose and where to choose from .

SELECT Prod_name  from Products;

The preceding statement uses the SELECT statement to retrieve a column named Pro_name from the Products table.

2) Retrieving multiple columns

SELECT Prod_id,prod_name,prod_price  from Products;

3) Retrieving all columns

SELECT *  from Products;

4) Retrieving different values

Use the DISTINCT keyword, which instructs the database to return only different values

SELECT DISTINCT vend_id  from Products;

  

5) Limit Results

SELECT Prod_name  from  5;

The preceding code uses the SELECT statement to retrieve a single column of data. LIMIT 5 Instructs the DBMS, such as MySQL, to return no more than 5 rows of data.

To get back 5 rows of data, you need to specify where to start and the number of rows to retrieve:

SELECT Prod_name  from  55;

The LIMIT 5 OFFSET 5 instructs the DBMS such as MySQL to return 5 rows of data from line 5th. The first number is the number of rows retrieved, and the second number refers to where to start.

  Note: The first row to be retrieved is the No. 0 row, not the 1th row. Therefore, the LIMIT 1 OFFSET 1 retrieves the 2nd row instead of the first row .

  

SQL must know

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.