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

  • Home
  • SEARCH
  • 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 8729283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:48:24+00:00 2026-06-13T08:48:24+00:00

I have a table like this: Item ProviderId Item1 1 Item1 2 Item2 1

  • 0

I have a table like this:

Item    ProviderId

Item1   1

Item1   2

Item2   1

Item3   1

I wish to get a new table. In the new table, it only lists the items who has at least two different ProviderIds.

So in the above example, since only item1 has two different ProviderId I wish to get table like this:

Item

Item1

How can I write the statement to do this?

  • 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-06-13T08:48:25+00:00Added an answer on June 13, 2026 at 8:48 am

    You have to use group by and having:

    select item
    from table
    group by item
    having count(distinct ProviderId)>=2
    

    or without distinct

    select item
    from tab
    group by item, ProviderId
    having count(1)>=2;
    

    sql fiddle demo

    With query as table:

    select item
    from (select item, ptoviderId from tabA) as tab
    group by item, ProviderId
    having count(1)>=2;
    

    If you want to create new table, you can use into:

    select item
    into newTable
    from table
    -- or (select item, ptoviderId from tabA)
    group by item
    having count(distinct ProviderId)>=2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a table like this: Item Number Collection Items in Collection 1234
I have a bill of materials table that is set up like this: item
I have a table like this (8 cells only for illustrative purposes, may be
I have a table like this: Item { int ItemID int ParentID string Name
I have a table like this: Item Name Name_location Price 1 item1_london london 10
I have a table that looks like this one : +------+------+------------------+ | item |
I have a stock transaction table like this: StockID Item TransDate TranType BatchNo Qty
I have a two-row table like this: --------------------------- | 1 Item | Total: $370.00
I have a query that returns items like this Item -- Code -- Thing
I have an invoice table like this: Bill Item Qty Weight Rate Amount Advance

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.