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. Database & SysAdmin
  3. Database
  4. SELECT Question

SELECT Question

Scheduled Pinned Locked Moved Database
questiondatabasesql-servercomannouncement
2 Posts 1 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
    MarkB777
    wrote on last edited by
    #1

    Hi, I'm trying to use the query below in MSSQL. SELECT [mxDelete],[mxContactID] FROM mxContact.dbo.Contacts WHERE mxContactID IN **(SELECT [mxContactID], [mxzCopies] FROM** (SELECT [mxContactID], [mxzCopies] FROM mxContact.dbo.Associations_Groups_to_Contacts WHERE mxGroupID='35EA110C-FE44-4A85-8D9A-AE973E2C5F85' OR mxGroupID='3CF66F58-F8E4-44CD-84A0-CB62F85E129B') **AS COL GROUP BY mxContactID HAVING (COUNT(mxContactID) > 1))** My question is, how can I make it so that the code in bold will give me the mxzCopies column as well. If I select just the contactID, then it works fine, but with the addition of mxzCopies, it gives me: Msg 8120, Level 16, State 1, Line 1 Column 'COL.mxzCopies' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Msg 116, Level 16, State 1, Line 1 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Cheers, Mark.

    Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog

    M 1 Reply Last reply
    0
    • M MarkB777

      Hi, I'm trying to use the query below in MSSQL. SELECT [mxDelete],[mxContactID] FROM mxContact.dbo.Contacts WHERE mxContactID IN **(SELECT [mxContactID], [mxzCopies] FROM** (SELECT [mxContactID], [mxzCopies] FROM mxContact.dbo.Associations_Groups_to_Contacts WHERE mxGroupID='35EA110C-FE44-4A85-8D9A-AE973E2C5F85' OR mxGroupID='3CF66F58-F8E4-44CD-84A0-CB62F85E129B') **AS COL GROUP BY mxContactID HAVING (COUNT(mxContactID) > 1))** My question is, how can I make it so that the code in bold will give me the mxzCopies column as well. If I select just the contactID, then it works fine, but with the addition of mxzCopies, it gives me: Msg 8120, Level 16, State 1, Line 1 Column 'COL.mxzCopies' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Msg 116, Level 16, State 1, Line 1 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Cheers, Mark.

      Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog

      M Offline
      M Offline
      MarkB777
      wrote on last edited by
      #2

      Nevermind figured it out. SELECT mxContactID, mxzCopies FROM ( SELECT [mxContactID], [mxzCopies] FROM mxContact.dbo.Associations_Groups_to_Contacts WHERE mxGroupID='35EA110C-FE44-4A85-8D9A-AE973E2C5F85' OR mxGroupID='3CF66F58-F8E4-44CD-84A0-CB62F85E129B' ) AS COL GROUP BY mxContactID, mxzCopies HAVING (COUNT(mxContactID) > 1)

      Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog

      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