Select/query Question for Access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billelev
    New Member
    • Nov 2006
    • 119

    #1

    Select/query Question for Access 2003

    hi,

    Does anyone know how you would select, from a table of data, only the distinct values for one field that always appear with each value in a second field?

    For example...Suppo se the data is the following

    Field1 Field2
    2 a
    3 a
    4 a
    1 b
    2 b
    3 b
    4 b
    1 c
    2 c
    4 c

    Because only 2 and 4 always occur for every value in the second field, the query would return:

    2 a
    4 a
    2 b
    4 b
    2 c
    4 c

    Any help much appreciated.
  • 3acks
    New Member
    • May 2007
    • 16

    #2
    oops

    . .
    Last edited by 3acks; Jun 7 '07, 04:20 PM. Reason: mis-read the question

    Comment

    • billelev
      New Member
      • Nov 2006
      • 119

      #3
      Does anyone have any ideas? I would imagine there is a very simple solution...

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Originally posted by billelev
        Does anyone have any ideas? I would imagine there is a very simple solution...

        I would be glad to see "a very simple solution".

        Here is my ugly one.

        Table: t1
        .f1 (Number)
        .f2 (Text)

        Query: qryF2s
        SELECT DISTINCT t1.f2 FROM t1;

        Query: qryDRF1s
        SELECT DISTINCTROW t1.f1 AS DRf1 FROM t1;

        Query: qryDRF1Count_vs _F2Count
        SELECT
        t1.f1 AS f1,
        t1.f2 AS f2,
        (SELECT Count(*) FROM qryDRF1s WHERE DRf1=f1) AS DRF1Count,
        (SELECT Count(*) FROM qryF2s) AS F2Count
        FROM t1;

        Query: qryResult (displays result)
        SELECT
        qryDRF1Count_vs _F2Count.f1,
        qryDRF1Count_vs _F2Count.f2
        FROM
        qryDRF1Count_vs _F2Count
        WHERE qryDRF1Count_vs _F2Count.DRF1Co unt=qryDRF1Coun t_vs_F2Count.F2 Count;

        Really nice question.

        Comment

        Working...