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 > Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-06-07, 12:24
philmetz philmetz is offline
Registered User
 
Join Date: Apr 2007
Posts: 15
Question Query

I got the following code but the summary functions is not correct:

PHP Code:
SELECT owner.owner_namereport.rent
FROM owner LEFT JOIN report
ON owner
.ownerid report.ownerid
ORDER BY owner_name ASC
COUNT
(*) FROM report
WHERE rent 
450
How do i do it?
Reply With Quote
  #2 (permalink)  
Old 05-06-07, 13:12
philmetz philmetz is offline
Registered User
 
Join Date: Apr 2007
Posts: 15
Also how do i join three tables?
Reply With Quote
  #3 (permalink)  
Old 05-08-07, 06:06
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
What are you trying to summarise exactly? As far as I can see you are trying to count the number of records available the table. At a guess I would say that's not the summation you are looking for.

In answer to your second question :
Code:
SELECT table1.column1
         , table2.column1
         , table3.column1
FROM table1 
JOIN table2 ON table1.column3=table2.column3
JOIN table3 ON table2.column2=table3.column2
WHERE <...>
Reply With Quote
  #4 (permalink)  
Old 05-08-07, 06:08
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Also it's worth noting that the order of your syntax is completely incorrect :

1. SELECT COLUMNS
2. FROM TABLES [+ JOINS]
3. WHERE CLAUSE
4. GROUP CLAUSE
5. ORDER BY CLAUSE
e.g.
Code:
SELECT owner.owner_name, report.rent, COUNT(*)
FROM owner 
LEFT JOIN report ON owner.ownerid = report.ownerid
WHERE rent > 450
ORDER BY owner_name ASC;
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