Home » SQL & PL/SQL » SQL & PL/SQL » SQL Query (merged)
SQL Query (merged) [message #419226] Thu, 20 August 2009 10:18 Go to next message
aniestar
Messages: 6
Registered: May 2005
Junior Member
Find the hard drive sizes that are equal among two or more PCs.
Result set: hd.


Table:
PC(code, model, speed, ram, hd, cd, price)

I tried the following query:

select hd, count(model) from PC group by hd having count(model) >= 2;

But I don't want to display count(model)

Re: SQL Query [message #419229 is a reply to message #419226] Thu, 20 August 2009 10:22 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Then don't select count(model)
Re: SQL Query (merged) [message #419230 is a reply to message #419226] Thu, 20 August 2009 10:27 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Think to post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Re: SQL Query [message #419231 is a reply to message #419229] Thu, 20 August 2009 10:31 Go to previous messageGo to next message
aniestar
Messages: 6
Registered: May 2005
Junior Member
But query is not going to work.


Find the hard drive sizes that are equal among two or more PCs.
Result set: hd.


Table:
PC(code, model, speed, ram, hd, cd, price)

I tried the following query:

select hd from PC group by hd having count(model) >= 2;




Re: SQL Query (merged) [message #419232 is a reply to message #419226] Thu, 20 August 2009 10:38 Go to previous messageGo to next message
niteshsabharwal
Messages: 17
Registered: June 2009
Location: Manchester, UK
Junior Member
Assuming code is your PK, following query will give distinct hd values that are common for more than one records

SELECT DISTINCT HD
FROM   pc pc1, 
       pc pc2
WHERE  pc1.hd = pc2.hd
AND    pc1.code <> pc2.code;
Re: SQL Query [message #419233 is a reply to message #419231] Thu, 20 August 2009 10:39 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
But query is not going to work.

Explain that and read and follow the guide.

Regards
Michel
Re: SQL Query (merged) [message #419234 is a reply to message #419232] Thu, 20 August 2009 10:49 Go to previous message
aniestar
Messages: 6
Registered: May 2005
Junior Member
Thanks. It worked.
Previous Topic: Call base type constructor
Next Topic: Passing XMLTYPE parameter to a Web service
Goto Forum:
  


Current Time: Thu Dec 08 12:23:43 CST 2016

Total time taken to generate the page: 0.10397 seconds