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. A simple query :( [modified]

A simple query :( [modified]

Scheduled Pinned Locked Moved Database
databasehelptutorialquestion
4 Posts 2 Posters 1 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.
  • X Offline
    X Offline
    xoxoxoxoxoxox
    wrote on last edited by
    #1

    I want to select categories with biggest id from the table below. For example, Diet should return 228 and excercise should return 225... I want distinct category with biggest id. id Category 9 Diet 218 Diet 228 Diet 8 Exercise 215 Exercise 225 Exercise 1 Investing 224 Investing 234 Investing 5 Movie 219 Movie 229 Movie Anybody can help me?? thanks in advance -- modified at 22:36 Thursday 13th July, 2006

    A 1 Reply Last reply
    0
    • X xoxoxoxoxoxox

      I want to select categories with biggest id from the table below. For example, Diet should return 228 and excercise should return 225... I want distinct category with biggest id. id Category 9 Diet 218 Diet 228 Diet 8 Exercise 215 Exercise 225 Exercise 1 Investing 224 Investing 234 Investing 5 Movie 219 Movie 229 Movie Anybody can help me?? thanks in advance -- modified at 22:36 Thursday 13th July, 2006

      A Offline
      A Offline
      Andrew Bleakley
      wrote on last edited by
      #2

      SELECT Category, MAX(id) AS MaximumID FROM dbo.TableName GROUP BY category should do the trick. that is of course assuming you are using SQL Server, best in future to specify the actual database (and version) it removes any doubt and ensures the answer you get is accurate

      X 1 Reply Last reply
      0
      • A Andrew Bleakley

        SELECT Category, MAX(id) AS MaximumID FROM dbo.TableName GROUP BY category should do the trick. that is of course assuming you are using SQL Server, best in future to specify the actual database (and version) it removes any doubt and ensures the answer you get is accurate

        X Offline
        X Offline
        xoxoxoxoxoxox
        wrote on last edited by
        #3

        thank you very much. This is exactly what i wanted. :)

        A 1 Reply Last reply
        0
        • X xoxoxoxoxoxox

          thank you very much. This is exactly what i wanted. :)

          A Offline
          A Offline
          Andrew Bleakley
          wrote on last edited by
          #4

          No worries, MAX is one of SQL Server's "aggregation" functions. There are lots - SUM, MIN, AVG etc etc and Grouping is a very powerful feature - definitly worth the time to look into and understand.

          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