[Learning Record] MySQL primary query statement (select,where)

Source: Internet
Author: User

The standard query statements are as follows

Select   Column name 1, column name 2, column name 3 from      table name

The statement returns all rows of the corresponding column in the table

If you want to retrieve all the columns in a table, you can use the *

Select *  from table name a

Because the table's non-code attributes allow duplication, it is found that there are duplicates in the search results, which can be filtered by distinct

Select distinct  from table name F

You can use the limit clause if you are only interested in the first few rows of the search results

select column name from   table name limit A, a,  b

This means that the output starts from line A with a total of B line elements, and if you do not provide a then start at line 1th

If you need to sort the results of a search, you can use the ORDER BY clause

Select column name A, column name B from    table name  order by column name B; Select column name A, column name B from    table name  orderby  desc;

That is, sorting according to column name B, plus desc for the reverse order, you can also follow the column name by commas separated by a second row sequence. For example, order by column name B desc, column name C

Data filtering via where

Select  Column name from    table name  where   name='a'

Note that if you need to sort the results, the where must precede the order by

Where-supported conditional actions

For example, the Select product from the products where the price between 5 and 10

Where also supports the determination of NULL values

Select product from products where attr is null

About where more advanced usage

where supports and and or operations between multiple conditions, but note that the and priority is higher than or, and if necessary, parentheses

The where also supports in and not

Select  Student from    stus  where   in (+) Select  Student from    stus  wherenot in     (18 ,)

It is worth noting that the first statement here matches age=18 or 20, and the second match is that age is neither equal to 18 nor equal to 20.

Instead of 18 to 20.

[Learning Record] MySQL primary query statement (select,where)

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.