mysql查询语句集

1. mysql 查询出某字段的值不为空的语句

 1.不为空

        select * from table where id <> "";

        select * from table where id != "";

2.为空

        select * from table where id ="";

        select * from table where isNull(id);

具体情况具体分析,如果字段是char或者varchar类型的,使用id=""可以的;

如果字段是int类型的,使用isNull会好些。        

 2. mysql查询语句,多字段去除重复的问题

SELECT DISTINCT(column) FROM tb_name

  使用 DISTINCT 关键字去掉重复记录具有较大的局限性。DISTINCT() 只能包含一个字段且查询结果也只返回该字段而非数据完整记

  可以尝试使用如下语法:

SELECT DISTINCT(column),column1,column2,... FROM tb_name

 该查询结果将返回列出的所有字段,但该查询往往使 column 的唯一性失效,且 column 1,column 2,… 不能放在 DISTINCT(column) 之前。

SELECT DISTINCT(user_company),`user_account`,`user_mobile` FROM `papa_member` GROUP BY user_company
原文地址:https://www.cnblogs.com/zhuiluoyu/p/5845541.html