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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:23:59+00:00 2026-05-25T17:23:59+00:00

I have a many-to-many relation with my database, so I created a sql query

  • 0

I have a many-to-many relation with my database, so I created a sql query which later I will use for search.
Now what I want to do is get a unique values from my search result (unique company names).

This is my query:

SELECT agencies.company
    ,agencies.website_url
    ,agencies.STATUS
    ,agencies.size
    ,IndustryData.industry_id
    ,ProfessionData.profession_id
    ,SectorData.sector_id
    ,seniorityData.seniority_id
    ,ZonesData.zone_id
FROM agencies
LEFT JOIN (
    SELECT agencies_industries.agency_id
        ,agencies_industries.industry_id
    FROM agencies_industries
    ) AS IndustryData ON agencies.id = IndustryData.agency_id
LEFT JOIN (
    SELECT agencies_professions.agency_id
        ,agencies_professions.profession_id
    FROM agencies_professions
    ) AS ProfessionData ON agencies.id = ProfessionData.agency_id
LEFT JOIN (
    SELECT agencies_sectors.agency_id
        ,agencies_sectors.sector_id
    FROM agencies_sectors
    ) AS SectorData ON agencies.id = SectorData.agency_id
LEFT JOIN (
    SELECT agencies_seniorities.agency_id
        ,agencies_seniorities.seniority_id
    FROM agencies_seniorities
    ) AS SeniorityData ON agencies.id = SeniorityData.agency_id
LEFT JOIN (
    SELECT agencies_zones.agency_id
        ,agencies_zones.zone_id
    FROM agencies_zones
    ) AS ZonesData ON agencies.id = ZonesData.agency_id
WHERE IndustryData.industry_id = 3
    AND ProfessionData.profession_id = 1

The result looks like this:

company, website_url, status, size, industry_id, profession_id, sector_id, seniority_id, zone_id

  1. Nine nine.com 1 3 3 1 3 2 1
  2. Nine nine.com 1 3 3 1 3 2 5
  3. Nine nine.com 1 3 3 1 3 2 8
  4. Nine nine.com 1 3 3 1 3 5 1
  5. Nine nine.com 1 3 3 1 3 5 5
  6. Nine nine.com 1 3 3 1 3 5 8
  7. Ten ten.com 2 3 3 1 3 1 1
  8. Ten ten.com 2 3 3 1 3 1 3
  9. Ten ten.com 2 3 3 1 3 1 7
  10. Ten ten.com 2 3 3 1 3 3 1
  11. Ten ten.com 2 3 3 1 3 3 3
  12. Ten ten.com 2 3 3 1 3 3 7
  13. Ten ten.com 2 3 3 1 3 5 1
  14. Ten ten.com 2 3 3 1 3 5 3
  15. Ten ten.com 2 3 3 1 3 5 7

I would like to get rid of the repeats of the company names. How do I do that?

  • 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-25T17:23:59+00:00Added an answer on May 25, 2026 at 5:23 pm

    You could use a GROUP BY for this, e.g.:

    SELECT agencies.company
        ,agencies.website_url
        ,agencies.STATUS
        ,agencies.size
        ,IndustryData.industry_id
        ,ProfessionData.profession_id
        ,SectorData.sector_id
    FROM ...
    GROUP BY agencies.company
        ,agencies.website_url
        ,agencies.STATUS
        ,agencies.size
        ,IndustryData.industry_id
        ,ProfessionData.profession_id
        ,SectorData.sector_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about Criteria method, one-to-many relation to the database, 'one' is
I have questions which are represented like this in my SQL database : CREATE
I have a core data database which has (for now) 2 entities Product and
when i have a many-to.many relation with nhibernate and let nhibernate generate my db
I have 2 tables having many to many relation and hence there is junction
Lets say I have two tables - child and parent with many-to-one relation. What
I have many items inside a list control. I want each item to have
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have a SQL Server database with two table : Users and Achievements. My
I have a mysql table with items in relation to their order. CREATE DATABASE

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.