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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:48:42+00:00 2026-06-09T17:48:42+00:00

The query I am trying to perform is With getusers As (Select userID from

  • 0

The query I am trying to perform is

With getusers As
    (Select userID from userprofspecinst_v where institutionID IN
    (select institutionID, professionID from userprofspecinst_v where userID=@UserID) 
    and professionID IN 
    (select institutionID, professionID from userprofspecinst_v where userID=@UserID))

    select username from user where userID IN (select userID from getusers)

Here’s what I’m trying to do. Given a userID and a view which contains the userID and the ID of their institution and profession, I want to get the list of other userID’s who also have the same institutionID and and professionID. Then with that list of userIDs I want to get the usernames that correspond to each userID from another table (user). The error I am getting when I try to create the procedure is, “Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.”. Am I taking the correct approach to how I should build 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-09T17:48:44+00:00Added an answer on June 9, 2026 at 5:48 pm

    The following query should do what you want to do:

    SELECT      u.username
    
    FROM        user AS u
    INNER JOIN  userprofspecinst_v AS up ON u.userID = up.userID
    INNER JOIN  (SELECT institutionID, professionID FROM userprofspecinst_v 
                     WHERE userID = @userID) AS ProInsts
                         ON (up.institutionID = ProInsts.institutionID 
                                     AND up.professionID = ProInsts.professionID)
    

    Effectively the crucial part is the last INNER JOIN statement – this creates a table constituting the insitutionsids and professsionids the user id belongs to. We then get all matching items in the view with the same institution id and profession id (the ON condition) and then link these back to the user table on the corresponding userids (the first JOIN).

    You can either run this for each user id you are interested in, or JOIN onto the result of a query (your getusers) (it depends on what database engine you are running).

    If you aren’t familiar with JOIN’s, Jeff Atwood’s introductory post is a good starting place.

    The JOIN statement effectively allows you to explot the logical links between your tables – the userId, institutionID and professionID are all examples of candidates for foreign keys – so, rather than having to constantly subquery each table and piece the results together, you can link all the tables together and filter down to the rows you want. It’s usually a cleaner, more maintainable approach (although that is opinion).

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

Sidebar

Related Questions

I'm trying to perform the following query in Sqlalchemy. Select * from "Mytable" where
So I am trying to perform this query on my database: select count(*) from
I'm trying to perform a DISTINCT clause on a query like this SELECT DISTINCT
I'm trying to perform an Ajax query from within a Greasemonkey script, but I'm
I'm trying to perform a select query over two tables, one containing, for example,
I am trying to perform two different SUMs within a single query. user points
I am trying to get ActiveRecord to perform the following query: SELECT A.*, B.*,
I am trying to perform the following query Create a view which restricts staff
I'm trying to perform a post query when the user leaves the page. The
The MySQL query I'm currently trying to perform is functionally equivalent to this: SELECT

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.