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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:55:23+00:00 2026-06-05T03:55:23+00:00

I have a notes table which stores notes about customers, jobs and products tables.

  • 0

I have a notes table which stores notes about customers, jobs and products tables.
Customers, jobs and products tables have “Name” and “Id” (GUID) columns.
I want to get a note and its related object name in one query. (If my note is related to a customer, the related object name would be customername, and so on.)

Is it possible to do this with a single query? If so, how?

  • 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-05T03:55:24+00:00Added an answer on June 5, 2026 at 3:55 am
    select
        notes.id,
        notes.content as content,
        coalesce(customers.name, jobs.name, products.name) as name,
        customers.id as customer_id,
        jobs.id as job_id,
        products.id as product_id
    from notes
        left outer join customers on notes.relatedobjid = customers.id
        left outer join jobs      on notes.relatedobjid = jobs.id
        left outer join products  on notes.relatedobjid = products.id
    ;
    

    Wrap this with some logic in the DAO / display code (python because it’s fairly easy to read):

    for row in query.list():
        if row["customer_id"] is not None:
            display_type = "customer name"
        elif row["job_id"] is not None:
            display_type = "job name"
        elif row["product_id"] is not None:
            display_type = "product name"
        display_note(display_type, row["name"], row["content"])
    

    The extra columns and display logic may or may not be necessary, depending on how attached you are to the idea of having it say “Customer name”. I’d probably keep it, personally. I think you could probably shuffle a lot of this logic off into your Object Relational Mapping if you have one. That may or may not be such a hot idea, depending on how many rows you have in the notes table.

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

Sidebar

Related Questions

Consider I have a table with notes which could be associated with zero or
I have two tables people name id man1 456 man2 123 man3 789 notes
I have two tables people name id man1 456 man2 123 man3 789 notes
I have a table which stores 'links' between 2 people. In order prevent further
I have a table Classes, which stores data on different college classes (a unique
I have a table Items which stores fetched book data from Amazon. This Amazon
I have a table in my database which stores a tree structure. Here are
I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have four tables in my database( notes , expense , category and items

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.