Results 1 to 4 of 4

Thread: Query

  1. #1
    Join Date
    Apr 2007
    Posts
    15

    Question Unanswered: 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?

  2. #2
    Join Date
    Apr 2007
    Posts
    15
    Also how do i join three tables?

  3. #3
    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 <...>

  4. #4
    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;

Posting Permissions

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