Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. conditional select statment

conditional select statment

Scheduled Pinned Locked Moved Database
questiondatabase
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Meax
    wrote on last edited by
    #1

    i have these data in the database table, Meetings MeetingID Details Hour Minute 1 Meeting Details1 14 10 2 Meeting Details2 14 15 how can i select all the fields of MeetingID 2? SELECT MeetingID, Hour, Minute, Details FROM Meetings WHERE (Hour = (SELECT MAX(Hour) FROM Meetings)) AND (Minute = (SELECT MAX(Minute) FROM Meetings)) but this code doesn't fetch any record

    J R 2 Replies Last reply
    0
    • M Meax

      i have these data in the database table, Meetings MeetingID Details Hour Minute 1 Meeting Details1 14 10 2 Meeting Details2 14 15 how can i select all the fields of MeetingID 2? SELECT MeetingID, Hour, Minute, Details FROM Meetings WHERE (Hour = (SELECT MAX(Hour) FROM Meetings)) AND (Minute = (SELECT MAX(Minute) FROM Meetings)) but this code doesn't fetch any record

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Of course it doesn't - the row with the max hour might not be the same row as the row with the max minute. If you stored the meeting time in a single field (of type datetime or smalldatetime) which would be the right solution, this would be easy.

      SELECT TOP 1 * FROM Meeting ORDER BY MeetingDateTime DESC

      As it is with your table you can just do

      SELECT TOP 1 * FROM MEeting Order BY Hour DESC, Minute DESC

      M 1 Reply Last reply
      0
      • M Meax

        i have these data in the database table, Meetings MeetingID Details Hour Minute 1 Meeting Details1 14 10 2 Meeting Details2 14 15 how can i select all the fields of MeetingID 2? SELECT MeetingID, Hour, Minute, Details FROM Meetings WHERE (Hour = (SELECT MAX(Hour) FROM Meetings)) AND (Minute = (SELECT MAX(Minute) FROM Meetings)) but this code doesn't fetch any record

        R Offline
        R Offline
        Rupesh Kumar Swami
        wrote on last edited by
        #3

        whether you search for MeetingID =2 or for which where Meeting time is maximum I think you want to get the all detail of meeting for which meeting time is highest. use following query SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings) hope this helps

        Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

        M J 2 Replies Last reply
        0
        • J J4amieC

          Of course it doesn't - the row with the max hour might not be the same row as the row with the max minute. If you stored the meeting time in a single field (of type datetime or smalldatetime) which would be the right solution, this would be easy.

          SELECT TOP 1 * FROM Meeting ORDER BY MeetingDateTime DESC

          As it is with your table you can just do

          SELECT TOP 1 * FROM MEeting Order BY Hour DESC, Minute DESC

          M Offline
          M Offline
          Meax
          wrote on last edited by
          #4

          thanks for helping out

          1 Reply Last reply
          0
          • R Rupesh Kumar Swami

            whether you search for MeetingID =2 or for which where Meeting time is maximum I think you want to get the all detail of meeting for which meeting time is highest. use following query SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings) hope this helps

            Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

            M Offline
            M Offline
            Meax
            wrote on last edited by
            #5

            thank you for helping out

            1 Reply Last reply
            0
            • R Rupesh Kumar Swami

              whether you search for MeetingID =2 or for which where Meeting time is maximum I think you want to get the all detail of meeting for which meeting time is highest. use following query SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings) hope this helps

              Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              Rupesh Kumar Swami wrote:

              SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings)

              :wtf: Why? Multiply the hour by 60 and add the minutes? If anything the other way round, surely?

              L R 2 Replies Last reply
              0
              • J J4amieC

                Rupesh Kumar Swami wrote:

                SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings)

                :wtf: Why? Multiply the hour by 60 and add the minutes? If anything the other way round, surely?

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                the math is fine, it is calculating minutes since midnight. On a big table it could be slow... :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                1 Reply Last reply
                0
                • J J4amieC

                  Rupesh Kumar Swami wrote:

                  SELECT * FROM mettings WHERE (hour*60+minute) =(select max(hour*60+minute) from mettings)

                  :wtf: Why? Multiply the hour by 60 and add the minutes? If anything the other way round, surely?

                  R Offline
                  R Offline
                  Rupesh Kumar Swami
                  wrote on last edited by
                  #8

                  J4amieC wrote:

                  Why? Multiply the hour by 60 and add the minutes?

                  if there are multiple records, for which Metting time is equal to Highest Metting time, then it display all records. However your suggestion is better.

                  Rupesh Kumar Swami Software Developer, Integrated Solution, Bikaner (India) My Company Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups