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
  1. Home
  2. General Programming
  3. LINQ
  4. Return max and min in the same query?

Return max and min in the same query?

Scheduled Pinned Locked Moved LINQ
databasequestioncsharplinqtutorial
2 Posts 2 Posters 2 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.
  • E Offline
    E Offline
    ErikZ
    wrote on last edited by
    #1

    Hi, If I have a table in my db, lets say it has the columns "name", "price", "quantity". How can i write a LINQ query that returns max/min price and min/max quantity in the same query? Anybody having an idea how to do this?

    P 1 Reply Last reply
    0
    • E ErikZ

      Hi, If I have a table in my db, lets say it has the columns "name", "price", "quantity". How can i write a LINQ query that returns max/min price and min/max quantity in the same query? Anybody having an idea how to do this?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Off the top of my head:

      from p in Purchases
      group p by p.Price into q
      select new { MaxPrice = q.Max(r=>r.Price), MinPrice = q.Min(p=>p.Price) }

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      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