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 8546881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:08:15+00:00 2026-06-11T13:08:15+00:00

There is a column in a table(contracts) called service location. I have to show

  • 0

There is a column in a table(contracts) called service location. I have to show all the rows where the service locations matches any other row in the table.

    Table Example

 A    B    C
 1    2    3
 3    2    1
 2    5    3

I require a query where the first and second rows will be returned based on a comparison on the second column. I am assuming I will need to use a HAVING COUNT(B) > 1

I came up with this

SELECT  `contract_number` 
FROM  `contracts` 
WHERE  `import_id` =  'fe508764-54a9-41f7-b36e-50ebfd95971b'
GROUP BY  `service_location_id` 
HAVING COUNT(`service_location_id` ) >1  

But it doesn’t generate what I exactly need.

  • 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-11T13:08:16+00:00Added an answer on June 11, 2026 at 1:08 pm

    Having would do it, but you would need to use it like this

    SELECT  *
    FROM    Contracts
            INNER JOIN
            (   SELECT  B
                FROM    Contracts
                GROUP BY B
                HAVING COUNT(*) > 1 -- MORE THAN ONE ROW WITH THE SAME VALUE
            ) dupe
                ON dupe.B = Contracts.B
    

    Depending in your indexing you may find a self join performs better though:

    SELECT  DISTINCT t1.*
    FROM    contracts t1
            INNER JOIN contract` t2
                ON t1.B = t2.B
                AND t1.A <> t2.A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to specify table column width as is. In other words,
I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot
I have a table where there is a column of type 'text'. I know
I have a database table named 'student' in which there is one column named
For example, I have a table, and there is a column named 'Tags'. I
I have problem with my application. I have table report, there are 2 column
There is one table , and I want the unique values of table column
There is a column that exists in 2 tables. In table 1, this column
In my table definition, there is a column with int data type. If a
Is there a way, using MySQL 5.0, to define a column in a table

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.