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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:49:11+00:00 2026-06-14T04:49:11+00:00

I have 3 tabels with the following definitions people —— – wid – name

  • 0

I have 3 tabels with the following definitions

people
------
- wid 
- name

types
-----
- guid
- type

mapping
-------
- guid
- wid

The people table has the list of people

The types table the type information for each row present in the people table. If a person belongs to more than one type, then two rows are present in the types table.

The mapping table provides a mapping between people and types table.

Now to find out who are the people of type ‘politician’ I can use the following query.

select name from people inner join 
(mapping inner join types on mapping.guid = types.guid) 
on people.wpid = mapping.wpid where types.type = 'politician'

But now I want to find out what are the other types a politician belongs. I know that I have to use group by and having clause. But I am not able to come up with the query. How to write this query?

  • 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-14T04:49:12+00:00Added an answer on June 14, 2026 at 4:49 am

    Try:

    select p.name, t2.type
    from types t1
    join mapping m1 on m1.guid = t1.guid
    join people p on p.wpid = m1.wpid 
    join mapping m2 on p.wpid = m2.wpid 
    join types t2 on m2.guid = t2.guid
    where t1.type = 'politician'
    order by 1, 2
    

    – for a list of all politicans and all the types that they belong to.

    Alternatively, if you just want a list of all politicians and the number of different types that they belong to, try:

    select p.name, count(*)
    from mapping m1
    join people p on p.wpid = m1.wpid 
    join mapping m2 on p.wpid = m2.wpid 
    where m1.guid = 1 /* replace 1 with appropriate guid for politicians */
    group by p.name
    order by 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with the following definitions: CREATE TABLE [dbo].[Shows] ( [Id] UNIQUEIDENTIFIER
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have three mysql table from same database Db1. Three tables have following columns.
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
Say I have two tables, user and comment . They have table definitions that
I have the following script to create a table in MySQL version 5.1 which
I have following tables in my database: SuggestionsLog Table: ID, Title, Description. Employee Table:
I currently have the following table definition: <table border=1 cellspacing=0 bordercolor=#CEDFEF cellpadding=1> I am
I have tables with following structure: -- Table structure for table `temp_app` -- CREATE

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.