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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:32:10+00:00 2026-05-19T01:32:10+00:00

Ok I know little about SQL so bear with me… I’m trying to see

  • 0

Ok I know little about SQL so bear with me…

I’m trying to see if certain values exist in a third level table and I don’t know how to go about it. Here is the scenario…

I have a Accident table that holds accident information. It has 3 one-to-many child tables (Units, Occupants, NonMotorists). An each of those child tables have their own many-to-many child table (Alcohol). I need to be able to have some way of seeing if a range of values exists in a field in those Alcohol tables. Here is watered down version of what my structure for the tables looks like…

--tblAccident--_  
PK_AccidentNumber    

--tblAccidentUnit--  
PK_PrimaryKey  
FK_AccidentNumber  

--tblAccidentOccupant--    
PK_PrimaryKey  
FK_AccidentNumber

--tblAccidentNonMotorist--  
PK_PrimaryKey  
FK_AccidentNumber

--tblAccidentUnitAlcohol--  
PK_PrimaryKey  
FK_ForeignKey  
AlcoholValue <---- THIS IS WHAT I NEED TO SEARCH   

--tblAccidentOccupantAlcohol--  
PK_PrimaryKey  
FK_ForeignKey  
AlcoholValue <---- THIS IS WHAT I NEED TO SEARCH   

--tblAccidentNonMotoristAlcohol--  
PK_PrimaryKey  
FK_ForeignKey  
AlcoholValue <---- THIS IS WHAT I NEED TO SEARCH 

I hope this makes some sense as to what i am trying to accomplish. thank you

  • 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-19T01:32:11+00:00Added an answer on May 19, 2026 at 1:32 am

    I assume you just want to get info from the third level table if the range exists.

    Try the query given below:

    Since the database is not specified am not sure if the BETWEEN operator in your database would includes the test values.

    SELECT  AccidentNumber, 'AccidentUnit' AS TableFound, c.PrimaryKey AS TableKeyValue
      FROM  tblAccident a INNER JOIN tblAccidentUnit b
          ON    a.AccidentNumber = b.AccidentNumber INNER JOIN tblAccidentUnitAlcohol c
            ON  b.PrimaryKey = c.ForeignKey
         AND    c.AlcoholValue BETWEEN <RANGE_START> AND <RANGE_END>
    UNION       
    SELECT  AccidentNumber, 'AccidentOccupant' AS TableFound, c.PrimaryKey AS TableKeyValue
      FROM  tblAccident a INNER JOIN tblAccidentOccupant b
          ON    a.AccidentNumber = b.AccidentNumber INNER JOIN tblAccidentOccupantAlcohol c
            ON  b.PrimaryKey = c.ForeignKey
         AND    c.AlcoholValue BETWEEN <RANGE_START> AND <RANGE_END>
    UNION
    SELECT  AccidentNumber, 'AccidentNonMotorist' AS TableFound, c.PrimaryKey AS TableKeyValue
      FROM  tblAccident a INNER JOIN tblAccidentNonMotorist b
          ON    a.AccidentNumber = b.AccidentNumber INNER JOIN tblAccidentNonMotoristAlcohol c
            ON  b.PrimaryKey = c.ForeignKey
         AND    c.AlcoholValue BETWEEN <RANGE_START> AND <RANGE_END>     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know very little about JavaScript but despite this I'm trying to cobble something
I know really little about sql, can anyone give me a deeper explanation (or
I know a little about SQL injections and URL decode, but can someone who's
I know a little about SNMP, but not enough. I need to develop an
First question on here so please be nice :) I know very little about
I just started thinking about creating/customizing a web crawler today, and know very little
I am a little curious to know about how OpenID authentication works. Is there
Now that LINQ to SQL is a little more mature, I'd like to know
I know it makes little difference to a project but, assuming you use #defined
I know this question might sound a little cheesy but this is the first

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.