MySQL - 資料查詢語句

來源:互聯網
上載者:User

標籤:strong   like   span   資料量   back   使用者名稱   concat_ws   查詢語句   mys   

資料查詢語句
select 列名,列名,列名… from 表名 [where條件]
列名是欄位的名字,注意最後一個列名不加逗號,表名後面的條件可加可不加,加了就只查出來滿足條件的資料。


查詢user表裡的使用者名稱和密碼
select user_name,password from user;
這個是只查了表裡的使用者名稱和密碼,並且沒有條件

添加where條件,查出滿足條件的所有欄位
select * from user where id=1;

 

過濾掉重複的值
select distinct mobile from user;
過濾user表裡的mobile欄位,有重複的就只查出來一個

連結欄位
select concat(user_name,mobile) from user;
把user_name 和手機號串連成一個欄位

指定串連後的欄位名
select concat(user_name,email) as user_name_email from user;

給欄位添加分割符 --
select concat_ws("--",user_name,email) from user;

 


欄位重新命名
select user_name as name,email as em from user;
把查出來的欄位user_name 重新命名為name 把email重新命名為em


模糊查詢(應用情境:搜尋)
Like適用於資料量小的查詢(10萬以內)
資料量大的使用Sphinx(另外一個技術)
select user_name from user where user_name like ‘%ng%‘;
查詢user_name欄位值裡帶ng的欄位值,% 代表不管你前面是什麼後面是什麼,只要value裡帶這個ng就會被查出來
%ng 代表左模糊 ng%代表右模糊 %ng%代表全模糊

 

---------------------------------------------------

 

MySQL - 資料查詢語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.