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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:47:00+00:00 2026-06-10T20:47:00+00:00

We need to create a view that combines both these SQL statements together. SELECT

  • 0

We need to create a view that combines both these SQL statements together.

SELECT g.state_cd, g.state_name, 
    case when s.ROLE_ID = 110 then 'Yes' else 'No' end  POC
    FROM us_state g
    LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
    and s.role_id = 110 


    SELECT g.state_cd, g.state_name, 
    case when s.ROLE_ID = 120 then 'Yes' else 'No' end  ADM
    FROM us_state g
    LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
    and s.role_id = 120 

Eg.

An user will have multiple rows. Some users will have role = 110 & some users will have role = 120 & some will have a combination of both. So is it possible to create 1 SQL statement that combines both of these. The result should be:

MD Maryland Yes No
NY Newyork No Yes
NJ Newhersey Yes Yes

The above table implies:

MD user has only role of 110
NY user has only the role of 120
NJ user has both roles.

Hope I’m clear on what is needed & it makes sense.

I tried to combine them like this:

SELECT g.state_cd, g.state_name, 
case when s.ROLE_ID = 110 then 'Yes' else 'No' end  POC,
case when s.ROLE_ID = 120 then 'Yes' else 'No' end  ADM
FROM us_state g
LEFT OUTER JOIN role s ON g.state_cd = s.OFC_STATE_CD
and s.role_id in (110, 120)

But this doesn’t work and it returns duplicate rows. Not sure what I’m missing here. I would appreciate it greatly if someone can help.

Thanks

Harish

  • 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-10T20:47:02+00:00Added an answer on June 10, 2026 at 8:47 pm

    You need to aggregate the results:

    SELECT g.state_cd, g.state_name, 
           max(case when s.ROLE_ID = 110 then 'Yes' else 'No' end) as POC,
           max(case when s.ROLE_ID = 120 then 'Yes' else 'No' end) as ADM
    FROM us_state g LEFT OUTER JOIN
         role s ON g.state_cd = s.OFC_STATE_CD and s.role_id in (110, 120)
    group by g.state_cd, g.state_name
    

    It turns out that “Yes” and “No” work well with MAX.

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

Sidebar

Related Questions

I need to create a View that represents an x/y axis. I will read
I understand that we need to create MXML file to define a view. Suppose
I need to create a view on the iPhone that scrolls horizontally through a
I need to create a view that automatically adds virtual row number in the
I need to create a view that show employees that have their Service anniversary
I have need of a view that combines two entity models. I created a
I need to create an activity(view) that shows several lists, for example: (text)Fruits: (item)apple
I need to create a view that lists out taxonomy terms and then list
I need to create a view that will automatically change from month to month
I need to create the list view that loads data dynamically based on scroll

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.