Click here to Skip to main content
15,899,679 members
Home / Discussions / Database
   

Database

 
GeneralRe: creating a bunch of tables from a central table Pin
Pyt8-Nov-02 10:17
Pyt8-Nov-02 10:17 
GeneralRe: creating a bunch of tables from a central table Pin
Vagif Abilov10-Nov-02 6:03
professionalVagif Abilov10-Nov-02 6:03 
GeneralRe: creating a bunch of tables from a central table Pin
Like2Byte11-Nov-02 2:34
Like2Byte11-Nov-02 2:34 
GeneralDataSets and XML Pin
Karen8-Nov-02 6:31
Karen8-Nov-02 6:31 
GeneralRe: DataSets and XML Pin
Rickard Andersson2010-Nov-02 20:57
Rickard Andersson2010-Nov-02 20:57 
GeneralRe: access to a mysql-database Pin
Vasudevan Deepak Kumar9-Nov-02 0:19
Vasudevan Deepak Kumar9-Nov-02 0:19 
GeneralSerious and Dreaded OleDB Adapter DB2 Driver Crashing Problem Pin
Vasudevan Deepak Kumar7-Nov-02 20:00
Vasudevan Deepak Kumar7-Nov-02 20:00 
GeneralTrivial SQL (i think) Pin
alex.barylski7-Nov-02 11:33
alex.barylski7-Nov-02 11:33 
I'm a newbie with SQL so please take it easy on me... Blush | :O

Anyways...

I have 2 tables

clients ( email, name, phone, address, agencyid )
agency ( agencyid, email, name, phone, address, website )

I need to pull all the agency records out and determine if they have clients/members...???

How would I do this...i'm so lost???

Currently I have something like:

SELECT agency, clients WHERE agency.agencyid = clients.agencyid AND this is where i'm lost


Is there anyway inside the SQL statement I can determine if an agency has no members...? This is what I need returned...agencies with no members...???

Do I have to use a for loop?
I'm using mySQL and PHP BTW
$query = "SELECT * agency";
$result = mysql_query($query); // Store all agencies inside result set
$row = mysql_fetch_array($result);

// Iterate all agencies and determine if they have members
for($i=0; $i<mysql_num_rows($result); $i++){
  $clientResult = mysql_query("SELECT * clients WHERE clients.agencyid = $row[$i].agencyid");
  if(mysql_num_rows($clientResult) == 0)
    // Store this record for display
}


Do I have to do it like the above or can I accomplish this from ONE SQL statement...? Or Am I doing it all wrong...?

Thanx! Smile | :)

"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
GeneralRe: Trivial SQL (i think) Pin
Paul Watson7-Nov-02 11:47
sitebuilderPaul Watson7-Nov-02 11:47 
GeneralRe: Trivial SQL (i think) Pin
alex.barylski7-Nov-02 12:58
alex.barylski7-Nov-02 12:58 
GeneralRe: Trivial SQL (i think) Pin
alex.barylski7-Nov-02 13:10
alex.barylski7-Nov-02 13:10 
GeneralRe: Trivial SQL (i think) Pin
Paul Watson7-Nov-02 21:08
sitebuilderPaul Watson7-Nov-02 21:08 
GeneralRe: Trivial SQL (i think) Pin
markkuk8-Nov-02 2:08
markkuk8-Nov-02 2:08 
GeneralRe: Trivial SQL (i think) Pin
alex.barylski8-Nov-02 8:11
alex.barylski8-Nov-02 8:11 
GeneralSELECT ... FOR XML AUTO Pin
Alexandru Savescu6-Nov-02 23:42
Alexandru Savescu6-Nov-02 23:42 
GeneralSaving a recordset in an XML stream Pin
Alexandru Savescu5-Nov-02 23:33
Alexandru Savescu5-Nov-02 23:33 
GeneralRe: Saving a recordset in an XML stream Pin
Richard Deeming6-Nov-02 2:54
mveRichard Deeming6-Nov-02 2:54 
GeneralDatasets Pin
Scoop5-Nov-02 23:15
Scoop5-Nov-02 23:15 
GeneralRe: Datasets Pin
Alexandru Savescu5-Nov-02 23:37
Alexandru Savescu5-Nov-02 23:37 
GeneralRe: Datasets Pin
Paul Watson6-Nov-02 3:15
sitebuilderPaul Watson6-Nov-02 3:15 
GeneralRe: Datasets Pin
Scoop6-Nov-02 3:23
Scoop6-Nov-02 3:23 
GeneralRe: Datasets Pin
Paul Watson6-Nov-02 3:26
sitebuilderPaul Watson6-Nov-02 3:26 
Generalfeedback from stored proc Pin
SimonS5-Nov-02 22:11
SimonS5-Nov-02 22:11 
GeneralRe: feedback from stored proc Pin
Richard Deeming6-Nov-02 3:15
mveRichard Deeming6-Nov-02 3:15 
GeneralRe: feedback from stored proc Pin
SimonS6-Nov-02 18:58
SimonS6-Nov-02 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.