Repeating in sql query, how to remove

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ntshoekeleng
    New Member
    • May 2012
    • 7

    Repeating in sql query, how to remove

    Code:
    SELECT ARTWORK.TITLE AS 'Title',ARTWORK.DATE_LISTED AS 'Date Listed',
    	ARTWORK.USUAL_TYPE as 'Type',ARTWORK.USUAL_MEDIUM as 'Medium', ARTWORK.USUAL_STYLE as 'Style',
    	ARTWORK.YEAR_COMPLETED as 'Year',ARTWORK_SALES.ASKING_PRICE as 'Asking Price'
    	
    	FROM ARTWORK_SALES,ARTWORK_SOLD
    	
    	INNER JOIN ARTWORK ON ARTWORK.ARTWORK_CODE=ARTWORK.ARTWORK_CODE
    	GROUP BY TITLE, ARTWORK.TITLE,ARTWORK.DATE_LISTED,ARTWORK.USUAL_TYPE,ARTWORK.USUAL_MEDIUM,ARTWORK.USUAL_STYLE,
    	ARTWORK.YEAR_COMPLETED,ARTWORK_SALES.ASKING_PRICE
    That is my code and i get the correct result but they repeat each row
    Last edited by Rabbit; May 31 '12, 03:33 PM. Reason: Please use code tags when posting code.
  • India777
    New Member
    • Apr 2012
    • 61

    #2
    Please Post your sample result for this Query

    Comment

    • Ntshoekeleng
      New Member
      • May 2012
      • 7

      #3
      Love lost 2011-07-12 00:00:00.000 Painting Oil Contempory 2011-05-15 00:00:00.000 15000.00
      Love lost 2011-07-12 00:00:00.000 Painting Oil Contempory 2011-05-15 00:00:00.000 150000.00
      My Queen 2011-10-10 00:00:00.000 Sculpture Mixed Folk 2009-08-17 00:00:00.000 15000.00
      My Queen 2011-10-10 00:00:00.000 Sculpture Mixed Folk 2009-08-17 00:00:00.000 150000.00
      Reality 2011-08-17 00:00:00.000 Sculpture Marble Impressionist 2010-05-28 00:00:00.000 15000.00
      Reality 2011-08-17 00:00:00.000 Sculpture Marble Impressionist 2010-05-28 00:00:00.000 150000.00

      Comment

      • India777
        New Member
        • Apr 2012
        • 61

        #4
        use distinct keyword after select keyword in Sql Query

        Example: Select distinct form tablename

        Comment

        • India777
          New Member
          • Apr 2012
          • 61

          #5
          oh Sorry i cant see Correctly.
          What you Actually want to Display in "Asking Price" Field

          Comment

          • Ntshoekeleng
            New Member
            • May 2012
            • 7

            #6
            still doesn't work..

            Comment

            • India777
              New Member
              • Apr 2012
              • 61

              #7
              The problem is with the field name "Asking Price". Because it Contain 15000.00 in first row then 150000.00 in Second Row. So group by cannot Work here.

              So What You want to Display in this Field Actually?

              Comment

              • Ntshoekeleng
                New Member
                • May 2012
                • 7

                #8
                Oh ok..Il see how i solve this one.

                Comment

                • India777
                  New Member
                  • Apr 2012
                  • 61

                  #9
                  What is the Common Field for ARTWORK_SALES and ARTWORK Tables.

                  Comment

                  • Ntshoekeleng
                    New Member
                    • May 2012
                    • 7

                    #10
                    The common field is artwork_code

                    Comment

                    • India777
                      New Member
                      • Apr 2012
                      • 61

                      #11
                      but why you check like this in inner join condition
                      ARTWORK.ARTWORK _CODE=ARTWORK.A RTWORK_CODE
                      Change this like
                      ARTWORK.ARTWORK _CODE=ARTWORK_S ALES.ARTWORK_CO DE.

                      You need to Sum the "Asking Price" in ARTWORK_SALES by ARTWORK_CODE Right?

                      Comment

                      • Ntshoekeleng
                        New Member
                        • May 2012
                        • 7

                        #12
                        Inner join artwork on artwork.artwork _code=artwork_s old.artwork_cod e

                        i have used this code and now it repeats twice and not for times

                        Comment

                        • India777
                          New Member
                          • Apr 2012
                          • 61

                          #13
                          ok Ntshoekeleng. Please Say What You need to Display in "Asking Price" field?
                          15000.00 or 150000.00 or Sum of this two Values(From Your Result).

                          Comment

                          • Ntshoekeleng
                            New Member
                            • May 2012
                            • 7

                            #14
                            The sum of the two values

                            Comment

                            • India777
                              New Member
                              • Apr 2012
                              • 61

                              #15
                              So You need to Change the Query. Please Remove "Asking Price" from Group by and put Sum(ARTWORK_SAL ES.ASKING_PRICE ) in Select Query. Please find this Link http://w3schools.com/sql/sql_func_sum.asp . Its help You To know about Sum() function in Sql.

                              Comment

                              Working...