Select statement RRS feed

  • Question

  • User129610786 posted

    Hi All,

        I have requirement to get a data from mysql server using select statement.

     I have table with data as below

    In gridview I should get the record only once.

    Please help me.



    table name is noofCLs

    empid     emailid                                  name                       leaves    month      year

    1002     bharat.reddy@yuself.net Allam Bharath 1             July        2013
    1003 sudhakar.goud@yuself.net      Sudhakar Goud V.       1             July        2013
    1001     sudhakar.reddy@yuself.net      Allam Sudhakar 0             August     2013
    1002 bharat.reddy@yuself.net Allam Bharath            1             June    2013
    1003 sudhakar.goud@yuself.net Sudhakar Goud V. 1             June    2013
    Saturday, June 22, 2013 7:13 AM

All replies

  • User665793701 posted

    Hello Yaswanth,

    Using distinct on your select statement will solve your proble.

    Select DISTINCT col1,col2...from noofCLs
    Saturday, June 22, 2013 7:33 AM
  • User1519811487 posted

    The data you have there will now allow you to get the record only once, as using a distinct on them columns will still give you the same output as you have.

    Are all the columns required in the GridView?

    Saturday, June 22, 2013 7:40 AM
  • User129610786 posted

    HI Mamuns,

    Firstly thanks for your reply. But by using Distinct we will not get the data only once because the month or leaves or year may differ with the same empid,name,emailid. so we get it twice.

    Saturday, June 22, 2013 7:45 AM
  • User129610786 posted

    Hi JammoD,

      As explained inabove post i will get the data how many times it is there in the database. Because distincit works if all the columns in the row is equal to the other row. If any one column data is changed then it will be repeated.

    Saturday, June 22, 2013 7:49 AM
  • User269602965 posted

    Since each person can have more than one record, with modifiers like date,

    which record do you want to keep.

    The one with the latest date?   The one with the highest leave value?

    Too bad MySql is a bit sparse in commands for analytics with partitioning, row ordering, etc.

    Saturday, June 22, 2013 6:26 PM
  • User-1972223072 posted

    select distinct empid,emailid,name,leaves,month,year from noofCLs

    Sunday, June 23, 2013 2:55 AM