1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to disregard a row in a returned MS Access query when all fields bar one are distinct

Discussão em 'Outras Linguagens' iniciado por Stack, Janeiro 27, 2021.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a query on Access 2010 which only produces a single row per patient. There are a really small number of patients (each patient represented by

    a unique nhs_number in the table n) who are listed as having 2 practices in the table pp and so two rows are generated for them. Is there a way I can arbitrarily select one of the practices and ignore the other?
    This is the query:

    SELECT DISTINCT
    n.nhs_number,
    IIF(ch.care_home_date>#2/1/1900#, "TRUE", "FALSE") AS care_home,
    pp.practice

    FROM (nhs_no_tbl AS n
    LEFT JOIN patient_practice_tbl AS pp ON n.nhs_number = pp.nhs_number)
    LEFT JOIN patient_care_home_tbl AS ch ON n.nhs_number = ch.nhs_number;


    The tables the query is using contains data along these lines:

    nhs_no_tbl:
    |nhs_number|
    | -------- |
    |1 |
    |2 |
    |3 |
    |4 |


    patient_practice_tbl:

    |nhs_number|practice|
    | -------- | ------ |
    |1 |GP_A |
    |2 |GP_A |
    |3 |GP_B |
    |4 |GP_A |
    |4 |GP_B |


    patient_care_home_tbl:

    |nhs_number|care_home_date|
    | -------- | ------------ |
    |1 |1/5/2000 |
    |1 |1/10/2010 |
    |4 |26/10/2017 |


    At the end, I'd like the query to return the following:

    |nhs_number|Care_home|practice|
    | -------- | ------- | ------ |
    |1 |TRUE |GP_A |
    |2 |FALSE | |
    |3 |FALSE | |
    |4 |TRUE |GP_A [or GP_B] |

    Continue reading...

Compartilhe esta Página