473,396 Members | 1,755 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,396 software developers and data experts.

Repeating in sql query, how to remove

Expand|Select|Wrap|Line Numbers
  1. SELECT ARTWORK.TITLE AS 'Title',ARTWORK.DATE_LISTED AS 'Date Listed',
  2.     ARTWORK.USUAL_TYPE as 'Type',ARTWORK.USUAL_MEDIUM as 'Medium', ARTWORK.USUAL_STYLE as 'Style',
  3.     ARTWORK.YEAR_COMPLETED as 'Year',ARTWORK_SALES.ASKING_PRICE as 'Asking Price'
  4.  
  5.     FROM ARTWORK_SALES,ARTWORK_SOLD
  6.  
  7.     INNER JOIN ARTWORK ON ARTWORK.ARTWORK_CODE=ARTWORK.ARTWORK_CODE
  8.     GROUP BY TITLE, ARTWORK.TITLE,ARTWORK.DATE_LISTED,ARTWORK.USUAL_TYPE,ARTWORK.USUAL_MEDIUM,ARTWORK.USUAL_STYLE,
  9.     ARTWORK.YEAR_COMPLETED,ARTWORK_SALES.ASKING_PRICE 
That is my code and i get the correct result but they repeat each row
May 30 '12 #1
17 2825
Please Post your sample result for this Query
May 30 '12 #2
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
May 30 '12 #3
use distinct keyword after select keyword in Sql Query

Example: Select distinct form tablename
May 30 '12 #4
oh Sorry i cant see Correctly.
What you Actually want to Display in "Asking Price" Field
May 30 '12 #5
still doesn't work..
May 30 '12 #6
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?
May 30 '12 #7
Oh ok..Il see how i solve this one.
May 30 '12 #8
What is the Common Field for ARTWORK_SALES and ARTWORK Tables.
May 30 '12 #9
The common field is artwork_code
May 30 '12 #10
but why you check like this in inner join condition
ARTWORK.ARTWORK_CODE=ARTWORK.ARTWORK_CODE
Change this like
ARTWORK.ARTWORK_CODE=ARTWORK_SALES.ARTWORK_CODE.

You need to Sum the "Asking Price" in ARTWORK_SALES by ARTWORK_CODE Right?
May 30 '12 #11
Inner join artwork on artwork.artwork_code=artwork_sold.artwork_code

i have used this code and now it repeats twice and not for times
May 30 '12 #12
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).
May 30 '12 #13
The sum of the two values
May 30 '12 #14
So You need to Change the Query. Please Remove "Asking Price" from Group by and put Sum(ARTWORK_SALES.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.
May 31 '12 #15
Expand|Select|Wrap|Line Numbers
  1. SELECT distinct ARTWORK.TITLE AS 'Title',ARTWORK.DATE_LISTED AS 'Date Listed',
  2. ARTWORK.USUAL_TYPE as 'Type',ARTWORK.USUAL_MEDIUM as 'Medium', ARTWORK.USUAL_STYLE as 'Style',
  3. ARTWORK.YEAR_COMPLETED as 'Year',ARTWORK_SALES.ASKING_PRICE as 'Asking Price'
  4.  
  5. FROM ARTWORK_SALES,ARTWORK_SOLD
  6.  
  7. INNER JOIN ARTWORK ON ARTWORK.ARTWORK_CODE=ARTWORK.ARTWORK_CODE
  8. GROUP BY TITLE, ARTWORK.TITLE,ARTWORK.DATE_LISTED,ARTWORK.USUAL_TY PE,ARTWORK.USUAL_MEDIUM,ARTWORK.USUAL_STYLE,
  9. ARTWORK.YEAR_COMPLETED,ARTWORK_SALES.ASKING_PRICE 
try this after ask me
May 31 '12 #16
sonurathore, please see the Result of the Query

Expand|Select|Wrap|Line Numbers
  1. Love lost 2011-07-12 00:00:00.000 Painting Oil Contempory 2011-05-15 00:00:00.000 15000.00
  2. Love lost 2011-07-12 00:00:00.000 Painting Oil Contempory 2011-05-15 00:00:00.000 150000.00
  3.  
Distinct is not Work here.
May 31 '12 #17
Rabbit
12,516 Expert Mod 8TB
Aren't you trying to SUM up the field? I don't see SUM anywhere in your code.

Also, please use code tags when posting code.
May 31 '12 #18

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

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
8
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
3
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the...
9
by: MLH | last post by:
I have a table (tblCorrespondence) holding records with fields like , , , , , , , etc... About a dozen 's are defined and I often use queries to extract records of a given . That's pretty easy....
13
by: guitarromantic | last post by:
Hey everyone. I'm editing some stuff I did last summer, trying to bugfix and improve stuff. One improvement (or an oversight of the original design) is adding dynamic <title> tags to my pages....
2
by: sbatschelet | last post by:
I am running into a really odd problem with Access and looking for some insight as to what could be causing my issue. Basically this SQL creates a listing of Total Sales (Sum(InvLine.Retail)) by...
1
by: vssp | last post by:
Hi friends Thanks for your repaly for all my question.. I need one update query. I have selected the datas are insert with coma ",". Query SELECT city FROM `locations` WHERE city REGEXP ','
5
by: monomaniac21 | last post by:
hi all On a networking site i am working on each user has their own id and the id of another person who they are linked to. what i want to do is to be able to pull up a list of everyone linked...
0
by: CJM | last post by:
I have a fairly simple ASP application talking to an Oracle 10g DB using a mixture of ADO (OraOLEDB) and OO4O - the query here concerns some ADO code. One part of the application records...
1
by: aaronkm | last post by:
Hello thescripts and well met. I've recently been handed a new duty and have the joy of 'crash coursing' MS Access. Things are working well but I've ran into a problem that I can't seem to find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.