SQL Query

  • I have a Result Table which Stores Draw Results.

    The prb is..I need to display the Latest 2 Draw Results in my webpage?

    I have DrawID,DrawDate,WinningNumbers.

    How do I do a SQL query to get the Latest 2 Draws?

    Thanks in advance?

  • SELECT TOP 2 DrawID,DrawDate,WinningNumbers FROM [Result Table] ORDER BY DrawID desc

    /**A strong positive mental attitude will create more miracles than any wonder drug**/

  • I need them to be seperate queries.

    SELECT TOP 2 DrawID,DrawDate,WinningNumbers FROM [Result Table] ORDER BY DrawID desc - retunrs me 2 Rows.

    I need 2 seperate queries. To give me the 1st Top row

    and another for the 2 top row.

  • Query 1 - >

    SELECT DrawID,DrawDate,WinningNumbers FROM [Result Table] WHERE

     DrawID IN (SELECT Max(DRAWID) From [Result Table])

     

    Query 2 - >

    SELECT DrawID,DrawDate,WinningNumbers FROM [Result Table] WHERE

     DRAWID IN (SELECT Max(DRAWID) FROM [Result Table] WHERE

     DRAWID not in (SELECT Max(DRAWID) From [Result Table]) )

     

     

    /**A strong positive mental attitude will create more miracles than any wonder drug**/

  • If you do not mind could you explain to me how this particular query works.. Thanks

  • Bro I find that there is a conflict now.

    2 Latest Records with Winning Numbers in it.

    Now I add in a new Record with No winning Number. This now will be the latest..

    But I need to select the Latest 2 Records with Numbers inside? How do i solve this problem?

  • You just need to add an additional WHERE condition to your queries.

    Query 1 - >

    SELECT DrawID,DrawDate,WinningNumbers FROM [Result Table] WHERE

     DrawID IN (SELECT Max(DRAWID) From [Result Table] where WinningNumbers <> '')

    Query 2 - >

    SELECT DrawID,DrawDate,WinningNumbers FROM [Result Table] WHERE

     DRAWID IN (SELECT Max(DRAWID) FROM [Result Table] WHERE

     WinningNumbers <> '' and DRAWID not in (SELECT Max(DRAWID) From [Result Table]) where WinningNumbers <> '')

    This will be OK if your WinningNumbers field is a string.  You'll have to adjust it if it is a number, but hopefully you get the idea.

    Phil

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 7 posts - 1 through 6 (of 6 total)

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