1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with SQL / my PhpMyAdmin

Discussion in 'MySQL' started by fullylucky, Oct 22, 2017.

  1. #1
    I plan to have my table have entries (rows) that get activated as time goes on.

    There's 4 colns.

    idnumber, startdate, enddate, paiduptodate
    row 1 1, 1/1/2017, 1/11/2017, 1/11/2017
    row 2 2, 12/11/2017, 1/05/2018, 12/02/2018
    row 3 3, 1/05/2018, 11/07/2018, NULL
    row 4 4, 11/07/2018, 10/09/2018, NULL

    as you can see the start date joins on from the end date of the last entry. and if one entry hasn't fully been paid out then it's still up to that row.

    How do I write an SQL statement for phpmyadmin to get the highest (max) startdate that has another coln (the paid up to date coln) isn't Null. e.g. In the example above, it would be row 2. row 2 is the active lease. I want to select that entry.
    Would I use max and group by? and if not isnull? <>?
    fullylucky, Oct 22, 2017 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Likes Received:
    Best Answers:
    Trophy Points:
    SELECT MAX(startdate) WHERE paiduptodate != NULL should work, I think? That should return one single row, however, if you have multiple startdates that are the same, this might return unexpected results.
    PoPSiCLe, Oct 22, 2017 IP