How to use group by?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wildheart
    New Member
    • Apr 2007
    • 4

    How to use group by?

    Im having a small problem using GROUP BY basically this is what i want to do:

    My two tables:

    ID PropertyNum PictureUrl
    1 1 ../../media/images/the villa/image1.jpg
    2 1 ../../media/images/the villa/image2.jpg
    3 2 ../../media/images/tester/oakVilla.jpg

    PropertyId Name
    1 The Villa
    2 Tester Villa

    I want to select a property each only once and one picture for it, so i use this query:

    <xsql:query>
    SELECT dbPropertyId, dbName, dbPropertyNum, dbPictureUrl

    FROM property, pictures

    GROUP BY dbPropertyId
    </xsql:query>

    The problem is that the group by does not work " ORA-00979: not a GROUP BY expression "

    But if i remove the GROUP BY then the query returns property 1 two times as there are two pictures. I have tried using distinct also but that does not work as the pictureURLs are distinct

    Does anyone have an idea how to get around this problem?
  • wel
    New Member
    • Apr 2007
    • 5

    #2
    hi, i do not speak english very well so ....
    i don't know if it can fix the problem but when using sql*plus environment, there are a command called BREAK

    Use the BREAK command to divide rows into sections and suppress duplicate values. To ensure that the BREAK command works effectively, use the ORDER BY clause to order the columns that you are breaking on.

    Syntax
    BREAK on column[|alias|row]
    - Clear all BREAK settings by using the CLEAR command:
    CLEAR BREAK
    Example:
    BREAK ON dbPropertyId;

    SELECT dbPropertyId, dbName, dbPropertyNum, dbPictureUrl

    FROM property, pictures

    [ORDER BY dbPropertyId, dbName, dbPropertyNum, dbPictureUrl];

    REM clear all formatting commands ...
    CLEAR BREAK;


    Note that :
    Group Functions Syntax
    SELECT [column,] group_function( column), ...
    FROM table
    [WHERE condition]
    [GROUP BY column* ]
    [ORDER BY column];
    *all the columns that appear in the "select clause" et that are not included in a group function must appear in the "group by clause".

    Comment

    Working...