Advanced queries in MySQL

Source: Internet
Author: User

Advanced queries in MySQL

Previously learned query syntax: Select field name from table name where condition

In fact, the syntax of the query varies a lot:

1. Select can query an expression, which is an operator + operand.

For example 1 + 1 2 * 3 2-1+5*9 math.random () * 1;

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/01/wKioL1eDQbaA96XUAAAoYetSPTQ030.png-wh_500x0-wm_3 -wmp_4-s_2267836656.png "title=" 1.png "alt=" Wkiol1edqbaa96xuaaaoyetsptq030.png-wh_50 "/>

As you can see, in the database, the string + string is not spliced, but the addition is calculated,

Try it and take ' 1 ' + ' A123 '.

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/84/02/wKiom1eDQcaxrJXcAAAtxzLq-XU286.png-wh_500x0-wm_3 -wmp_4-s_3328902615.png "title=" 2.png "alt=" Wkiom1edqcaxrjxcaaatxzlq-xu286.png-wh_50 "/>

Expand, what if you want to make two strings of stitching?

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/01/wKioL1eDQdTQW0eAAAAq0tcFqAI332.png-wh_500x0-wm_3 -wmp_4-s_1144463910.png "title=" 3.png "alt=" Wkiol1edqdtqw0eaaaaq0tcfqai332.png-wh_50 "/>

2. Aliases for tables

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/84/02/wKiom1eDQeGwCiwyAABCNdbtsuw021.png-wh_500x0-wm_3 -wmp_4-s_261748804.png "title=" 4.png "alt=" Wkiom1edqegwciwyaabcndbtsuw021.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/01/wKioL1eDQe6xPinHAAAt_-6UBVs650.png-wh_500x0-wm_3 -wmp_4-s_2324194150.png "title=" 6.png "alt=" Wkiol1edqe6xpinhaaat_-6ubvs650.png-wh_50 "/>

In fact, the column can also alias:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/02/wKiom1eDQf2yw2BKAAArpezMTSo942.png-wh_500x0-wm_3 -wmp_4-s_2598760721.png "title=" 7.png "alt=" Wkiom1edqf2yw2bkaaarpezmtso942.png-wh_50 "/>

3. Use of the dual table.

Do we need to write out the name of the table when we query the expression?

No, it looks like this:

Select;

MySQL has a virtual table dual that complements the syntax of the query expression (the most appropriate syntax for those who have OCD!). )

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/02/wKiom1eDQgjCxA_OAAAt_ani0cg682.png-wh_500x0-wm_3 -wmp_4-s_3717135950.png "title=" 8.png "alt=" Wkiom1edqgjcxa_oaaat_ani0cg682.png-wh_50 "/>

Actually, do not add dual also line! Just for the integrity of the grammar.

When you query an expression, you can query more than one expression at a time.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/84/02/wKiom1eDQhewSXJYAABGmGZyGeM735.png-wh_500x0-wm_3 -wmp_4-s_2267959029.png "title=" 9.png "alt=" Wkiom1edqhewsxjyaabgmgzygem735.png-wh_50 "/>

query expressions, which can be combined with the data in a table.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/01/wKioL1eDQiThC-RBAABGmGZyGeM566.png-wh_500x0-wm_3 -wmp_4-s_1453433351.png "title=" 9.png "alt=" Wkiol1edqithc-rbaabgmgzygem566.png-wh_50 "/>

Similarly:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/84/02/wKiom1eDQjKjFvbnAAAxAhHUSF0654.png-wh_500x0-wm_3 -wmp_4-s_3548462090.png "title=" 10.png "alt=" Wkiom1edqjkjfvbnaaaxahhusf0654.png-wh_50 "/>

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/01/wKioL1eDQrmCYyZCAAcbFP5oG78092.jpg-wh_500x0-wm_3 -wmp_4-s_2864353765.jpg "style=" Float:none; "title=" Weibo copy copy of replica copy white version. jpg "alt=" Wkiol1edqrmcyyzcaacbfp5og78092.jpg-wh_50 "/>

Excellent Yue Group (Shenzhen) Co., Ltd.

Enjoy Life with technology

: Yojoygroup

Weibo: Http://weibo.com/YOJOYGROUP

Official website: http://www.yojoygroup.com/

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/02/wKiom1eDQrnSMBBNAAD6oXEMpqA031.jpg-wh_500x0-wm_3 -wmp_4-s_2103442774.jpg "style=" Float:none; "title=" priority yue. jpg "alt=" wkiom1edqrnsmbbnaad6oxempqa031.jpg-wh_50 "/>




Advanced queries in MySQL

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.