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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:32:46+00:00 2026-05-30T22:32:46+00:00

I have three table in the Database – Activity table with activity_id, activity_type Category

  • 0

I have three table in the Database –

  1. Activity table with activity_id, activity_type
  2. Category table with category_id, category_name
  3. Link table with mapping between activity_id and category_id

I need to write a select statement to get the following data:

activity_id, activity_type, Category_name.

The issue is some of the activity_id have no entry in the link table.

If I write:

select a.activity_id, a.activity_type, c.category_name 
from activity a, category c, link l 
where a.activity_id = l.activity_id and c.category_id = l.category_id

then I do not get the data for the activity_ids that are not present in the link table.
I need to get data for all the activities with empty or null value as category_name for those not having any linking for category_id.

Please help me with it.

PS. I am using MS SQL Server DB

  • 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-30T22:32:47+00:00Added an answer on May 30, 2026 at 10:32 pm

    I believe you’re looking for a LEFT OUTER JOIN for your activity table to return all rows.

    SELECT
    a.activity_id, a.activity_type, c.category_name 
    FROM activity a
    LEFT OUTER JOIN link l 
    ON a.activity_id = l.activity_id
    LEFT OUTER JOIN category c
    ON c.category_id = l.category_id; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql database with three tables I need to combine in a
i have a table Users in database. it have three colu mns Id (bigint)
Say I have a database table with three columns: ID, Name, and Age. I
I have three tables in my database. First table is Employee : Second table
i have created a testimonial table in database .i have inserted three testimonials. I
I have a database table with three fields: Product(ProdId, Name, Price) Where ProdId is
I have a SQL Server 2008 database table with three varchar Columns - Col1,
I have three tables in my database. A users table, StoreA and StoreB StoreA
I have a database with three tables: user_table country_table city_table I want to write
I have three database tables: users emails invitations Emails are linked to users by

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.