Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Unhappy Unanswered: Check if rows are empty or full

    Hi,

    Firstly i have 2 tables for my websms app.

    One table stores just the names of the users groups(like an address book). - wsmsgroups Fields:
    userid - users unique id
    name - name of group(PK because no duplicates)


    The other table store there numbers with name and group for contact. - wsmscontacts

    Fields:
    userid - users unique id
    cgroup - group name
    contact - contacts name
    cellno - cellular number(PK)

    Now my problem:

    I need to get the groups that have contacts. A group might exist if it has no contacts. But I only want the groups that have one or more rows in wsmscontacts table.

    Thanks

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    name - name of group(PK because no duplicates)
    If more than one user can belong to a group then it isn't a good primary key, use userid instead.

    Also in your second table if a user can share a cell number with someone else it also isn't a good primary key. It is if no one can share a number.

    For your join, use a left outer join and test for not null

    Code:
    SELECT name FROM wsmsgroups
    LEFT OUTER JOIN
    wsmscontacts
    ON wmsgroups.userid = wsmscontacts.userid
    AND contact IS NOT NULL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •