Results 1 to 3 of 3
  1. #1
    daniel.preda is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2009
    Location
    Montreal
    Posts
    11

    Please help!

    I need help making a query: I have a table like this:
    _________ -----> ________
    |nam|val| -----> |nam|val|


    ----------- ----> ----------
    | a1 | 7 | -----> | a1 | 7 |
    | a1 | 0 | -----> | a1 | 3 |
    | a1 | 3 | -query | b1 | 0 |
    | b1 | 0 | -----> | c1 | 9 |
    | b1 | 0 | -----> ----------
    | c1 | 0 |
    | c1 | 9 |
    ---------
    So basicly I need all non-zero values, but add just one line of every name if all the values are zeroes.

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    You have to do it in a few separate steps:

    first do your SelectQuery for >0 which give you:
    | a1 | 7 |
    | a1 | 3 |
    | c1 | 9 |

    save that query as say 'NoZeroQuery'

    then make a new query with your table joined to NoZeroQuery so the join arrow points at the query which forces in all values of the table...

    | a1 | 7 |
    | a1 | 3 |
    | b1 | |
    | c1 | 9 |

    b1 will be null.....and then add a nz method turning the null into a zero....

    hopefully this gets you going.

  3. #3
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Hi,

    This can be achieved by joining the two tables through a query with LEFT JOIN relation property where your table1 will join to table2 with the
    LEFT JOIN PROPERTY (2-including all records from table1 and only those records from table2 where join field are equal)

    The second (2) option in Relationship property where all records from Left side table is joining the right hand side table with the LEFT JOINT property. You will notice the Arrow head sign (>) between such relationships.

    SELECT Table1.Field1, Table2.Field1, Table1.Field2, Table2.Field2
    FROM Table1 LEFT JOIN Table2 ON Table1.Field1 = Table2.Field1;
    Hope this helps

    Best Regards,
    Khalid Afridi

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums