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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:47:24+00:00 2026-05-29T15:47:24+00:00

I have a table structure like the following: table a: id int name varchar

  • 0

I have a table structure like the following:

table a:
id int
name varchar

table b:
id int
name varchar

table c:
id int
valid tinyint
table_a int
table_b int

Basically, table c maps between table a and b and also has a column to determine if something is valid (either a 1 or 0). I want to be able to select every name (only once) from table a and the linked ‘valid’ column from table c (and default to 0 if it doesn’t exist) and limit it by matching table_b to an id. Hopefully that makes sense.


Here is some example data to help show what I mean:

Using the table structure as above I have this data:

Table a:
(id, name)
1, row 1
2, row 2
3, row 3

Table b:
(id, name)
1, row a
2, row b

Table c:
(id, valid, table_a, table_b)
1, 1, 1, 1

Now, what I want to select is all of the names from table a, the ‘valid’ column from c (default to 0 if no row that matches) and limit the ‘valid’ fields by only those that table_b = 1. Hopefully that makes more sense?

So, I want back the following where b.id = 1:

(a.name, c.valid)
row 1, 1
row 2, 0
row 3, 0
  • 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-29T15:47:24+00:00Added an answer on May 29, 2026 at 3:47 pm

    Let me see if I got it. Are you looking for something like this?

    This query:

    select a.name, coalesce(c.valid, 0) as IsValid, b.id from a
    left join c on a.id = c.table_a
    left join b on b.id = c.table_b
    

    Results in this:

    NAME    ISVALID ID
    row 1   1       1
    row 2   0   
    row 3   0   
    

    If you want all b.id = 1 then you WILL NOT have ALL rows from table_a.

    select a.name, coalesce(c.valid, 0) as IsValid from a
    left join c on a.id = c.table_a
    left join b on b.id = c.table_b
    where b.id = 1
    
    NAME    ISVALID ID
    row 1   1       1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL table with basically the following structure: PK (int, primary key),
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a ms-sql table with the following structure: Name nvarchar; Sign nvarchar; Value
I have an SQL table with the following structure: Code1 - int Code2 -
I have a table with the following structure leave_id int(10) No user_id int(10) No
I have the following table structure: CREATE TABLE a ( a_id int(10) unsigned NOT
I have a Tickets table with somewhat following structure (removed unnecessary columns) int |
I have a tree-style database with the following structure: Table fields: NodeID int ParentID

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.