Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:19:38+00:00 2026-05-27T10:19:38+00:00

I have a table defined like this CREATE TABLE OrderItemRoomings( OrderItemRoomingId int IDENTITY(1,1) NOT

  • 0

I have a table defined like this

CREATE TABLE OrderItemRoomings(
    OrderItemRoomingId int IDENTITY(1,1) NOT NULL,
    OrderItemId int NOT NULL,
    PaxId int NOT NULL,
    GroupNumber tinyint NOT NULL)

I’m trying to get all OrderItemId which, when grouped, have differents group numbers

Assuming this table

+-----------------------------------+
| OrderItemId | PaxId | GroupNumber |
+-----------------------------------+
| 101         | 501   | 1           |
+-----------------------------------+
| 101         | 502   | 1           |
+-----------------------------------+
| 102         | 503   | 2           |
+-----------------------------------+
| 102         | 504   | 2           |
+-----------------------------------+
| 103         | 505   | 1           |
+-----------------------------------+
| 103         | 506   | 2           |
+-----------------------------------+

I want the query to returns 103 because there are two different group number for id 103.

I can’t figure out the GROUP BY query which would check all sub result detail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:19:39+00:00Added an answer on May 27, 2026 at 10:19 am
    SELECT OrderItemId
    FROM MyTable
    GROUP BY OrderItemID
    HAVING COUNT(DISTINCT GroupNumber) > 1
    

    Use HAVING to do filtering on grouped sets. Here we show only orderitemid records with more than one unique groupnumber value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table defined like this: CREATE TABLE mytable (id INT NOT NULL
I have a User table defined like this: CREATE TABLE Users( UserId int IDENTITY(1,1)
I have a table defined like this: create table users ( id int(10), age
Imagine to have a table defined as CREATE TABLE [dbo].[Price]( [ID] [int] NOT NULL,
I have a table defined by: CREATE TABLE bar_table ( _id INTEGER NOT NULL
I have a sqlite3 full text search table defined like this: CREATE VIRTUAL TABLE
I've defined table with this schema : CREATE TABLE [dbo].[Codings] ( [Id] [int] IDENTITY(1,1)
In MSSQL I have a table created like this: CREATE TABLE [mytable] (fkid int
Supposedly I have a table called Person defined like this: CREATE TABLE Persons (
I've a table which is defined like this CREATE TABLE [dbo].[MyTable]( [MyTableId] [bigint] IDENTITY(1,1)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.