How to get the first date of my table?

  • Hai friends,

    i ve the table like below

    create table student

    (

    class_atttend datetime,

    name varchar(20)

    )

    insert into student values ('02-07-2013', 'A')

    insert into student values ('03-07-2013', 'A')

    insert into student values ('04-07-2013', 'A')

    insert into student values ('05-07-2013', 'A')

    insert into student values ('06-07-2013', 'A')

    insert into student values ('07-07-2013', 'A')

    insert into student values ('08-07-2013', 'A')

    my required output is from the firstdate of where was appeared on it?

    expecting output:

    ===========

    02-07-2013

  • Homework assignment?

    Just use a GROUP BY in combination with a MIN statement.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • hai friend,

    actually i ve two tables

    like

    create table student

    (

    attendence datetime,

    name varchar(10),

    student_id varchar(20)

    )

    insert into student values ('02-07-2013', 'A')

    insert into student values ('03-07-2013', 'A')

    insert into student values ('04-07-2013', 'A')

    insert into student values ('05-07-2013', 'A')

    insert into student values ('06-07-2013', 'A')

    insert into student values ('07-07-2013', 'A')

    insert into student values ('08-07-2013', 'A')

    create table homework

    (

    attendence datetime,

    subject varchar(20),

    student_id varchar(20)

    )

    insert into student values ('02-07-2013', 'Maths')

    insert into student values ('03-07-2013', 'Maths')

    insert into student values ('04-07-2013', 'Maths')

    insert into student values ('05-07-2013', 'Maths')

    insert into student values ('06-07-2013', 'Maths')

    insert into student values ('07-07-2013', 'Maths')

    insert into student values ('08-07-2013', 'Maths')

    so i made join query

    select

    min(a.attendence) as workdays,

    b.subject

    from

    student a

    inner join

    homework b

    on

    a.student_id = b.student_id

    group by

    a.attendence,

    b.subject

    its showing output of

    02-07-2013 maths

    03-07-2013 maths

    what is the problem...................

  • You have to remove column [attendence] from the GROUP BY because you are aggregating these values with the MIN statement.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **

Viewing 4 posts - 1 through 3 (of 3 total)

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