Results 1 to 5 of 5

Thread: SQL string question

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    SQL string question

    I nearly have my problem figured out, but have one question…

    My SQL statement reads as follows:

    sql = "SELECT * FROM upcoming_dvd order by stdate,title asc"

    What I want is for it to display the earliest Street Date (stdate) in the DB and only that date and then order those by title (so if the earliest stdate is 2/17/2004, then display all those titles that have that street date). But I’m having trouble doing that. Any ideas as to what my SQL statement would be?

    So I guess I want to select a distinct date (the earliest in the DB) and only display that date and the titles associated with it.

    Any ideas?

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Maybe this work?


    Code:
    sql = "SELECT * FROM upcoming_dvd where stdate in (select top 1 stdate from upcoming_dvd order by stdate) order by stdate,title asc 
    
    ' I am not sure
    if this wont work, then try this
    sql = "SELECT * FROM upcoming_dvd where stdate in (select top 1 stdate from upcoming_dvd order by stdate desc) order by stdate,title asc

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    For an access database...

    sql = "SELECT TOP 1 * FROM upcoming_dvd order by stdate,title asc"

    ... returns first record based on order.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4
    That worked, all I had to do was change the desc to asc. But other than that, it worked perfectly.

    Thanks so much!

  5. #5
    Lively Member
    Join Date
    Jul 2002
    Location
    California
    Posts
    77
    Sorry to interupt, but once you create the stringed sql statement, how do you get it to execute?

    I must add to this. I'm coding in a stored procedure. So this is in Transact-SQL.

    Thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width