Order by error

  • error:

    ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

    the above error occured when i execute the query for same column name and order by class

    example

    select distinct emp_code,emp_name,emp_desig,emp_salary,active_flg

    from emp_mst

    where active_flg='a'

    and emp_code between '001' and '009'

    order by emp_code,emp_name,emp_desig,emp_salary,active_flg

    what is the problem occur the above query, pls sent me the exact reason

  • Hi

    I just tried exactly your statement and it works fine:

    DECLARE @emp_mst TABLE (

    emp_code VARCHAR(100),

    emp_name NVARCHAR(100),

    emp_desig INT,

    active_flg VARCHAR(20),

    emp_salary MONEY

    )

    INSERT INTO @emp_mst VALUES ('001', 'John', 1, 'a', 12.34)

    select distinct emp_code,emp_name,emp_desig,emp_salary,active_flg

    from @emp_mst

    where active_flg='a'

    and emp_code between '001' and '009'

    order by emp_code,emp_name,emp_desig,emp_salary,active_flg

    Maybe the error occurres at another position in your script. Did you have a look at the specified line number of the error message? Try to search for "DISTINCT" within your whole script/procedure.

    Greets

    Flo

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply