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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:21:03+00:00 2026-06-15T10:21:03+00:00

tblProjects is linked to tblPrCat with t1_id -columns in both tables. tblCategories is linked

  • 0

tblProjects is linked to tblPrCat with t1_id-columns in both tables.
tblCategories is linked to tblPrCat with t3_id-columns in both tables.
A project may have several categories.

tblProjects
t1_id
t1_name

tblPrCat
t1_id
t3_id

tblCategories
t3_id
t3_name

I’m trying to use a single SELECT-sentence to get the value of a project (or 10) AND get all the names of the categories corresponding to each project.

Is this possible in a single SELECT-sentence returning a single row per project but multiple categories?

  • 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-15T10:21:03+00:00Added an answer on June 15, 2026 at 10:21 am

    You can try a query like this:

    SELECT
        tblProjects.name AS project,
        tblCategories.name AS category
    FROM
        tblProjects
        INNER JOIN tblPrCat USING (t1_id)
        INNER JOIN tblCategories USING (t3_id)
    WHERE
        /* Your search criteria here */
    

    Note: you’ll see every category name associated with each project, but if there are more than one category per project, you’ll see what appear to be duplicate project names. Be ready to deal with this in your code.

    Edit:
    I had assumed (probably wrongly) that every project has at least one category. To ensure you also see project names with none, use this instead:

    SELECT
        tblProjects.name AS project,
        IFNULL(tblCategories.name, 'No categories!') AS category
    FROM
        tblProjects
        LEFT JOIN tblPrCat USING (t1_id)
        LEFT JOIN tblCategories USING (t3_id)
    WHERE
        /* Your search criteria here */
    

    Edit:
    To show each project only once, but show a summary of category names as a comma-separated list, use this:

    SELECT
        tblProjects.name AS project,
        IFNULL(GROUP_CONCAT(tblCategories.name), 'No categories!') AS category
    FROM
        tblProjects
        LEFT JOIN tblPrCat USING (t1_id)
        LEFT JOIN tblCategories USING (t3_id)
    WHERE
        /* Your search criteria here */
    GROUP BY
        tblProjects.t1_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called tblProducts with 3 columns: intID, dateMain, intStatus. I have
I have 2 tables in a database. I use following query: Select U.id, U.ad,
I have a table with products and their descriptions in several languages. For now
Possible Duplicate: SQL Server: Get Top 1 of Each Group I have 2 tables
I have very simple form along with two database tables. In this form is
I have two tables and I have to join it. table structures are tblproducts
I have a procedure like below DROP PROCEDURE IF EXISTS mp_search_result; CREATE PROCEDURE mp_search_result()
I have the following select statement where I need to sum each task from
I have a strange thing over here. I'm trying to insert a value in
I have a simple stored procedure like so: ALTER PROCEDURE [dbo].[spList_Report] @id INT AS

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.