如何编写查询选择值而不重复相同的值?

时间:2015-06-17 06:52:19

标签: mysql sql select

我需要从此表中选择employee_id,如果有00001是四次,我只需要获取一次。

如何为此方案编写查询?

id  company_ID  Employee_ID Name        Relationship    Dob     Age Gender       
    1   EMPL        00001       Choodamani  Spouse      11-Aug-66   49  Female            
    2   EMPL        00001       Komala      Mother      30-Oct-39   76  Female            
    3   EMPL        00001       Varshini    Daughter    29-Apr-04   11  Female            
    4   EMPL        00001       Vasudevan   Employee    15-Jul-62   53  Male    
    5   EMPL        00002       Siddharth   Son         1-Jun-00    15  Male              
    6   EMPL        00002       Poongavanam Mother      21-Oct-39   76  Female            
    7   EMPL        00002       Aruna       Spouse      16-Sep-68   47  Female            
    8   EMPL        00002       Abirami     Daughter    7-May-97    18  Female            
    9   EMPL        00002       Murali      Employee    7-Oct-67    48  Male

3 个答案:

答案 0 :(得分:2)

您可以使用distinct关键字:

SELECT DISTINCT Employee_ID FROM Employees

答案 1 :(得分:1)

您可以尝试distinct

select distinct Employee_ID from tbl

答案 2 :(得分:0)

select DISTINCT Employee_ID from tablename