SQL question.

Discussion in 'OT Technology' started by deusexaethera, Nov 17, 2009.

  1. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    SQL is just one of those things I've never quite been able to grasp properly.

    In this case, I have two tables:

    QUERY_MINOR
    --------------
    id
    query_major
    query_minor

    MITIGATION_MEASURES
    -----------------------
    id
    ...
    query_major
    query_minor
    ...

    - - -

    MITIGATION_MEASURES is the main table, and QUERY_MINOR is a lookup table. MITIGATION_MEASURES.query_minor should show a pick-list of values from QUERY_MINOR.query_minor, but I want the pick list to be filtered to only include records where QUERY_MINOR.query_major = MITIGATION_MEASURES.query_major field in the active row. How the hell do I do this?
     
  2. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    if i understand your question correctly, which i probably don't given your obfuscated explanation, you should do something like this:

    select a.query_minor from mitigation_measures a inner join query_minor b on a.query_major = b.query_major
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I'll try again to explain. Like I said, SQL is not my thing.

    Let's say the user selected "Bomb Detection" for the query_major field. I want the query_minor field to display a pick-list of records from the QUERY_MINOR table that fall under the "Bomb Detection" category.

    I don't understand what you're doing with the letters 'a' and 'b' in the query you posted. What are they for?
     
  4. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i'm just giving aliases for those table names so i don't have to keep calling them mitigation_measures and query_minor
     
  5. HardTech

    HardTech hungry

    Joined:
    May 5, 2000
    Messages:
    28,103
    Likes Received:
    1
    Location:
    NorCal
    you want SQL to display a picklist?

    hmm.. I think you're mixing up the technologies. You can return a list of QUERY_MINOR values if QUERY_MAJOR is a particular value:

    Code:
     select distinct query_minor.query_minor where mitigation_measure.query_major = query_minor.query_major
    are you talking about a particular application? Like Access or Excel?
     
  6. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Yes, it's in Access. When the user clicks in the query_minor field, I want Access to grab the value from the query_major field in the same record and show a filtered list of records from the lookup table that have matching query_major values.
     

Share This Page