473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cannot avoid duplicate results

I have 3 tables (Items, ItemProperties and ItemPropertyKeys). ItemPropertyKeys contains of property keys like title, quantity, author for the items and ItemProperties contains the actual property (the name of the author, the title of the item etc.) There could be more than one property refering to one key for a single item (for example the item could have more than one names).

Example:
Item SomeSong
ItemPropertyKey title
ItemProperty #1 with key title -> "Lalala"
ItemProperty #2 with key title -> "Bla bla bla"

Wanted Result:
Item Key Title
SomeSong title "Lalala"(or "Bla bla bla")

Received Result so far
Item Key Title
SomeSong title "Lalala"
SomeSong title "Bla bla bla"

I need to select items (for example by date range) and theirs titles but if an item has more than one title I need to select only one of them.
I've tried everything so far and had no luck. And also I shouldn't use stored procedures.

Hope I've been clear enough.

Help will be appreciated.

Thanks in advance.
Apr 1 '08 #1
13 1553
amitpatel66
2,367 Expert 2GB
Could you please post your source code that you have tried do far?
Apr 1 '08 #2
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",ITEMPROPERTY AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDATE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:start AND IDO.DOWNLOADEDDATE<=:end ))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
  3.  
This is one of my not working scripts and here's the result:
ID Date Type Title Value
1031 2008-03-27 Melodies Hladna Nejnost 1
1031 2008-03-27 Melodies Хладна нежност 1
1040 2008-03-31 Application GGG 1
1060 2008-04-01 Melodies Hladna Nejnost 1
1060 2008-04-01 Melodies Хладна нежност 1


The items with 1031 and 1040 ids are duplicated because they have 2 titles. I need to avoid this and result should contain only one of the titles no matter which one.
Apr 3 '08 #3
amitpatel66
2,367 Expert 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDA  TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END ))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE ORDER BY DOWNLOADEDDATE
  2.  
Apr 3 '08 #4
Still doesn't work
I've tried it with min too but the result was the same
Apr 3 '08 #5
amitpatel66
2,367 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT ITEMID AS "ItemId",TO_DATE(DOWNLOADEDDATE) AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDA    TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END ))GROUP BY ITEMID,TO_DATE(DOWNLOADEDDATE),ITEMTYPE ORDER BY DOWNLOADEDDATE
  3.  
Apr 3 '08 #6
I'm getting this:

Error starting at line 1 in command:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT ITEMID AS "ItemId",TO_DATE(DOWNLOADEDDATE) AS "Date",ITEMTYPE AS "Type",MAX(ITEMPROPERTY) AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM 
  3. ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM 
  4. (SELECT I.ITEMID,IT.ITEMTYPE,ITP.ITEMPROPERTY,DOWNLOADEDDATE FROM 
  5. ITEMDOWNLOADS IDO 
  6. JOIN ITEMS I ON I.ITEMID=IDO.ITEMID  
  7. JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID  
  8. JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') 
  9. JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' 
  10. JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID 
  11. WHERE IDO.DOWNLOADEDDATE>='2008-03-02' AND IDO.DOWNLOADEDDATE<='2008-04-03' ))
  12. GROUP BY ITEMID,TO_DATE(DOWNLOADEDDATE),ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
  13. Error at Command Line:11 Column:71
  14. Error report:
  15. SQL Error: ORA-00979: not a GROUP BY expression
  16. 00979. 00000 -  "not a GROUP BY expression"
  17. *Cause:    
  18. *Action:
  19.  
Apr 3 '08 #7
Just removed TO_DATE from the GROUP BY clause but it still returns duplicate results.
Apr 3 '08 #8
amitpatel66
2,367 Expert 2GB
Just removed TO_DATE from the GROUP BY clause but it still returns duplicate results.
How is your date stored in the database? with the time stamp or only date?
Apr 3 '08 #9
In the database it's just date.
Apr 3 '08 #10
amitpatel66
2,367 Expert 2GB
Try This:
Expand|Select|Wrap|Line Numbers
  1. SELECT ITEMID AS "ItemId",DOWNLOADEDDATE AS "Date",ITEMTYPE AS "Type",ITEMPROPERTY AS "Title", SUM(DOWNLOADS) AS "Downloads" FROM ( SELECT ITEMID,DOWNLOADEDDATE, ITEMTYPE, ITEMPROPERTY, DECODE (((DOWNLOADEDDATE-TO_DATE('2008-03-02')-ABS(DOWNLOADEDDATE-TO_DATE('2008-03-02'))+TO_DATE('2008-04-03')-DOWNLOADEDDATE-ABS(TO_DATE('2008-04-03')-DOWNLOADEDDATE))), 0, 1, 0) DOWNLOADS FROM (SELECT I.ITEMID,IT.ITEMTYPE,MAX(ITP.ITEMPROPERTY),DOWNLOADEDDA  TE FROM ITEMDOWNLOADS IDO JOIN ITEMS I ON I.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTIES ITP ON ITP.ITEMID=IDO.ITEMID  JOIN ITEMPROPERTYKEYS ITPK ON ITPK.ITEMPROPERTYKEYID=ITP.ITEMPROPERTYKEYID AND (ITPK.ITEMPROPERTYKEY='Title') JOIN PROVIDERS P ON P.PROVIDERID=I.PROVIDERID AND P.PROVIDER='TestProvider' JOIN ITEMTYPES IT ON IT.ITEMTYPEID=I.ITEMTYPEID WHERE IDO.DOWNLOADEDDATE>=:START AND IDO.DOWNLOADEDDATE<=:END GROUP BY  ITEMID,DOWNLOADEDDATE, ITEMTYPE))GROUP BY ITEMID,DOWNLOADEDDATE,ITEMTYPE,ITEMPROPERTY ORDER BY DOWNLOADEDDATE
  2.  
Try this query. I am guessing because I cannot test in my machine without table structures and data.
Apr 3 '08 #11
Still no change
Thanks for your time though
Apr 3 '08 #12
amitpatel66
2,367 Expert 2GB
I would suggest you to take out the property and select only other tables in your query. then add the table for item property and join your inline view and this table externally.....Just select one row of item property for each id.
Apr 3 '08 #13
Thanks for the help.
Apr 7 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: hjyn | last post by:
Hi All, I create a form for the user to enter the information, the form contains two table, table A and table B. I wrote a script to prompt the user to fill all the necessary data if they miss to...
1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
39
by: Chetan Raj | last post by:
Hi All, One of my friend asked this question on C++ >>> Hi, Can u give an answer to this : We have the .h files for standard library. Consider any class (such as
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
6
by: Dave | last post by:
I really don't like the users getting an unhandled expception page, and I'm still to new with ASP.Net and C#. So please accept my appology for the 2 part question. SqlException (0x80131904) ...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.