New topic: 

Need help With SQL Query.

<http://forums.realsoftware.com/viewtopic.php?t=46893>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        Antonio          Post subject: Need help With SQL Query.Posted: 
Sun Feb 10, 2013 10:11 am                         
Joined: Sat Feb 04, 2012 1:26 pm
Posts: 85
Location: Italy                Hi, 
I have three different tables. 
Table 1 contains ID, Name
Table 2 contains ID, Status  (status may be "checked" or nil)
Table 3 contains ID, Customer 

I need to populate a listbox with:
ID (from table1); 
name (from table1); 
Status (from table2; cell must contain the word "Checked" if present or must be 
blank if not present);
the count of how many times ID from table1 is present in Table3;

I used the following SQL code:
SELECT Table1.NAME, Table2.STATUS, Count(Table3.CUSTOMER) AS ConteggioDiCUSTOMER
  FROM (Table2 RIGHT JOIN Table1 ON Table2.ID = Table1.ID) LEFT JOIN Table3 ON 
Table1.ID = Table3.ID
  GROUP BY Table1.NAME, Table2.STATUS;


I had this issue: the count (field of table3) I get, seems to be the result of 
a multiplication of how many times the Id is present in table2. If an ID is 
present 3 times inside Table3, the count returns 6 instead of 3, because, that 
ID is present two times inside table2. Maybe a Cartestian product beetween 
table2 and table3?  how to avoid that?
Thanks for any help, 
Antonio   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to