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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:08:54+00:00 2026-06-02T13:08:54+00:00

I have a few tables in my database: user table: user_id (primary key) ,

  • 0

I have a few tables in my database:

  1. user table: user_id (primary key), first_name, last_name, email_address.
  2. inst table: inst_id (primary key), inst_name, and type.
  3. user_insts table: user_insts_id (primary key), user_insts_status, inst_name (foreign key) and user_id(foreign
    key)
    .

I’m using this on my website and i need it to display all of the entrys in the inst_name column for the inst table, but only the entrys for a certain id in the right side or else show as null. I’ve tried a few things like below:

SELECT inst.inst_name,inst.inst_id,user_insts.user_id,user_insts.inst_name 
FROM inst LEFT JOIN user_insts ON inst.inst_name=user_insts.inst_name;

SELECT inst.inst_name,inst.inst_id,user_insts.user_id,user_insts.inst_name 
FROM inst LEFT JOIN user_insts ON inst.inst_name=user_insts.inst_name 
WHERE user_insts.user_id='11';

Any help would be greatly appreciated.

EDIT::

this is what i currently get:

 inst_name  inst_id user_id:
 ASB          1        11
 BNZ          3        11
 FMG          5        11

i was hoping to be able to get something more like this:

 inst_name  inst_id user_id:
 ASB           1       11
 ANZ           2      NULL
 BNZ           3       11
 paymark       4      NULL
 FMG           5       11
 STATE         6      NULL
  • 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-02T13:08:55+00:00Added an answer on June 2, 2026 at 1:08 pm

    Do your provided queries show the following results?

    1. Query 1 : Shows all inst + user_insts entries but unfiltered by user_id
    2. Query 2 : Shows just the inst + user_insts entries filtered by user_id

    What’s happening in Query 2 is that the where clause filters the joined tables AFTER they are joined. I guess what you want to happen is to first filter the right side of the result (user_insts) by a specific user_id like so:

    SELECT ui.inst_name, ui.user_id FROM user_insts ui WHERE ui.user_id = :PARAM
    

    Then, you want to LEFT JOIN this with all the entries in the inst table AFTER the filter. You could use an inner view in order to filter by user_id first before the actual joining to the inst table. The resulting query should be something like this:

    SELECT i.inst_name, filtered_ui.user_id
    FROM  inst i
    LEFT JOIN (SELECT ui.inst_name, ui.user_id
               FROM user_insts ui
               WHERE ui.user_id = :PARAM) filtered_ui
    ON i.inst_name = filtered_ui.inst_name
    

    Thinking about it more, I’m not too familiar with MySQL so I’m not sure if this alternative query is valid syntax:

    SELECT i.inst_name, ui.user_id
    FROM inst i
    LEFT JOIN user_insts ui ON i.inst_name = ui.inst_name AND ui.user_id = :PARAM
    

    … which may be simpler than an inner view.

    The main point is you have to do the filtering first before joining, so that all the inst_names will be displayed.

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

Sidebar

Related Questions

So I have a database with a few tables. The first table contains the
I have a database with few tables, ex.: Employee (Id, Name, state, country) Material
I have a MS Access database with few tables and a form. When more
I have several database tables that just contain a single column and very few
I have a MySQL database with a few (five to be precise) huge tables.
I have quite a few situations where I have database structures similar to: TABLE
i have database table with few text fields which i use to filter data
I have a few tables in a MySQL database similar to this setup: major
We have a few tables with persisted computed columns in SQL Server. Is there
I have a few tables with 70-80 columns in them. I would like to

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.