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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:52:27+00:00 2026-05-28T07:52:27+00:00

I am trying to write a SQL query that pulls from 3 tables and

  • 0

I am trying to write a SQL query that pulls from 3 tables and haven’t been able to achieve the results I need. I want to return all the property names (labels) that are paired with a particular category and pair those properties with the values from a particular asset from the said category, which may not have a value to pair with each property.

I want all the properties for category 4, paired with the values for asset 135. Asset 135 doesn’t have values set for property 3 or 4, so I want:

| property_name | property_value     |  
|:--------------|:-------------------|  
| Fixture ID    | A5                 |  
| Manufacturer  | Black & Decker     |  
| Model #       |                    |  
| Type          |                    |

Here is my query:

SELECT property.property_name, asset_property.property_value
FROM property
LEFT OUTER JOIN category_property
ON property.property_id = category_property.property_id
INNER JOIN asset_property
ON asset_property.property_id = property.property_id
WHERE category_property.category_id = 4
AND asset_property.asset_id = 135

resulting data:

| property_name | property_value     |  
|:--------------|:-------------------|  
| Fixture ID    | A5                 |  
| Manufacturer  | Black & Decker     |  

It’s missing 2 of the properties because of my AND asset_property.asset_id = 135

Here are the tables:
* asterisk just indicates rows from test case.

table: property

| property_id | property_name |  
|:-----------:|:--------------|  
| 1           | Fixture ID    |*  
| 2           | Manufacturer  |*  
| 3           | Model #       |*  
| 4           | Type          |*  
| 5           | Lamp Type     |  

table: asset_property
pairs assets with property values.

| asset_id | property_id | property_value |  
|:--------:|:-----------:|:---------------|
| 129      | 1           | A5             |  
| 129      | 2           | Black & Decker |  
| 129      | 3           | 1230-02        |  
| 129      | 4           | Incandescent   |  
| 135      | 1           | E6             |*  
| 135      | 2           | Linden         |*  
| 147      | 1           | G1             |  

table: category_property
pairs categories with its properties.

| category_id | property_id |  
|:-----------:|:-----------:|  
| 4           | 1           |*  
| 4           | 2           |*  
| 4           | 3           |*  
| 4           | 4           |*  
| 7           | 2           |  
| 7           | 5           |  

I’ve tried all the different JOIN types, HAVING, GROUP BY….can’t it figure out. If anyone understand what I need, I’d really appreciate the help! Thanks!


To clarify, I need to return these sets of results:

| property_name |  
|:--------------|  
| Fixture ID    |  
| Manufacturer  |  
| Model #       |  
| Type          |  

AND

| property_value |  
|:---------------|  
| A5             |  
| Black & Decker |  

And join them on property_id:

| property_name | property_value |  
|:--------------|:---------------|  
| Fixture ID    | A5             |  
| Manufacturer  | Black & Decker |  
| Model #       |  
| Type          |  

But since there is no record for property_id 4 and 5 in the asset_property table, the property_name for those properties aren’t shown.

| property_name | property_value |  
|:--------------|:---------------|  
| Fixture ID    | A5             |  
| Manufacturer  | Black & Decker |  

Model #
Type

I want them to e shown. I want ALL the property names for Category 4 to be returned and be paired with any matching property_values for Asset 135.


So for the Fruits Category I want all the properties names returned (Color, Season, Taste). The color property for Apple is not set, but I still want all the property types to be returned, so they can be changed or filled out:

| property_name | property_value |  
|:--------------|:---------------|  
| Color         |                |  
| Season        | Fall           |  
| Taste         | Tart           |  
  • 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-28T07:52:27+00:00Added an answer on May 28, 2026 at 7:52 am

    Just change the INNER JOIN to a LEFT OUTER JOIN, and move AND asset_property.asset_id = 135 from the WHERE clause to the ON clause:

    SELECT property.property_name,
           asset_property.property_value
      FROM property
     INNER
      JOIN category_property
        ON property.property_id = category_property.property_id
      LEFT
     OUTER
      JOIN asset_property
        ON asset_property.property_id = property.property_id
       AND asset_property.asset_id = 135
     WHERE category_property.category_id = 4
    ;
    

    (I’ve also changed the first LEFT OUTER JOIN to an INNER JOIN, since the WHERE category_property.category_id = 4 will (correctly) filter out records where the join fails, anyway.)

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

Sidebar

Related Questions

I am trying to write some SQL that pulls from several tables using unions,
I am trying to write a SQL query that returns rows from a table
I'm trying to write an SQL query that would search within a CSV (or
I'm trying to write sql that produces the desired result from the data below.
I'm trying to write a custom SQL query that will create a list of
I'm trying to write a Microsoft SQL Server 2005 query that counts a total
I'm trying to write a linq-to-sql query using || that behaves the same way
Im trying to write an SQL query that will check in the table ‘persons’
I'm trying to write a sql query that shows how often two teams have
I'm trying to write a HQL/Criteria/Native SQL query that will return all Employees that

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.