简体   繁体   English

从表中获取所有唯一记录

[英]fetch all the unique record from table

I have an mysql query. 我有一个mysql查询。 I need fetch the all "eid" where "aid" not equal to "15" . 我需要获取所有的“ eid” ,其中“ aid”不等于“ 15” My table is like below. 我的桌子如下。 The result should be in group. 结果应在组中。 Example if aid != 15 then We should get only "eid" = 3 and 4 . 例如,如果aid!= 15,那么我们应该只获得“ eid” = 34

id | eti | aid | eid | val
1  |  2  |  15 |  1  |  WDC
2  |  2  |  11 |  1  |  USA
3  |  2  |  9  |  1  |  XYX
4  |  2  |  15 |  2  |  LDN
5  |  2  |  11 |  2  |  UK
6  |  2  |  9  |  2  |  ABC
7  |  2  |  11 |  3  |  China
8  |  2  |  9  |  3  |  HNB
9  |  2  |  18 |  4  |  China
10 |  2  |  12 |  4  |  HNB

Anybody help me? 有人帮我吗 Thanks in advance... 提前致谢...

select eid
from your_table
group by eid
having sum(aid = 15) = 0

The query below should help you: 以下查询将为您提供帮助:

select 'aid' from 'table'
  where 'eid' not in
    (select 'eid' from 'table'
       where 'aid'='15')
  group by 'eid';

You can use Distinct keyword. 您可以使用Distinct关键字。 Your query will become: 您的查询将变为:

 SELECT DISTINCT(eid) FROM <Your_table_name> WHERE aid != 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM