MySQL學習 2 select

來源:互聯網
上載者:User

標籤:表名   tom   排列   添加   targe   form   學習   ice   soc   

select 限制結果

SELECT prod_name

FROM products

LIMIT 5;

得到的結果就是只給出5個結果

650) this.width=650;" title="tmp6A17" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="tmp6A17" src="http://s3.51cto.com/wyfs02/M00/8D/CB/wKiom1iqwmDAPZzRAABJzkyiYFo945.png" "325" height="183" />

如果要從第五行開始的五行

SELECT prod_name

FROM products

LIMIT 5.5;

~

LIMIT 1,1 將檢索出第二行,而不是第一行

~

LIMIT 10,5 但是只有13行

那mysql將只返回他能返回的那麼多行

~

另外還有 使用完整表名

~

排序檢索資料

select prod_name

form products;

結果一般將以它在底層表出現的順序顯示,可以是最初添加到表中的順序,也會受到mysql重新回收儲存空間的影響

可以使用order by子句

select prod_name

form products

order by prod_name;  #將prod_name以字母順序排序

按多個列排序

看下面的例子,先以prod_price排序,可以看出按照價格排序了

出現2個10.00 ,這兩條依照prod_name的字母順序排列,bird在前,TNT在後

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/8D/CB/wKiom1iqwmHSocQ7AAE3YeYaURc157.png" "590" height="422" />

指定排序方向

select prod_id , prod_price, prod_name

form products

order by prod_price DESC; #其中DESC就是降序排列

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/8D/C8/wKioL1iqwmGAR40RAAF-6bonUMs708.png" "482" height="372" />

以上可以看到prod_price已經是降序排了(從大到小)

另外多列,需要看這列是否指定了降序,否則還是正著來

650) this.width=650;" title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/8D/C8/wKioL1iqwmKBbi91AAHn1BY_YIc139.png" "533" height="524" />

與DESC相反的是ASC(升序)但是沒啥卵用,因為預設的就是升序

例子

在一個表裡找到最昂貴的值

select prod_price

form products

order by prod_price DESC #降序排 最高的價格會在最上面

limit 1; #只出來一個價格

MySQL學習 2 select

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.