If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Check if rows are empty or full

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-04, 04:42
Akorz Akorz is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
Unhappy 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
Reply With Quote
  #2 (permalink)  
Old 07-10-04, 10:49
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Quote:
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On