Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove double entries from Query 1

Status
Not open for further replies.

NavMen

Vendor
Jul 6, 2004
35
NL
Hi,

I try to get only one row from a table, when I run “select PhysicalFile, Size_KB from SQLDBSIZE” I get all the physical file locations:

C:\Program Files\Microsoft SQL Server\MSSQL. \MSSQL\DATA\WSS_Content_Partners.mdf
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_Partners.mdf
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_Partners.mdf
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_Partners.mdf
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_STEALTH.mdf

But sometimes this location will pop up multiple times. I need then only once this entry. I don’t know how to do this.

Thanks,

Navmen
 
I found the answer:

select distinct(PhysicalFile), Size_KB from STH_SQLDBSIZE

solves my problem.

Thanks
 
Hi,

Still a small problem, how can I get the SUM of the Size_KB

select distinct(PhysicalFile), SUM(Size_KB/1048576) from STH_SQLDBSIZE

This still gives me the SUM of all the files, I need only from unique entries?

Thanks,

Navmen
 
If its the same value change quey to

select PhysicalFile, maximum(Size_KB/1048576) from STH_SQLDBSIZE
group by PhysicalFile

Ian

 
Ian,

Thanks,this gives the size of only one file.

The query: select distinct(PhysicalFile), Size_KB/1048576 from STH_SQLDBSIZE

Gives:

C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_Partners.mdf 0.08807373
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\WSS_Content_STEALTH.mdf 0.04705810

Now I need only the total of all files?

Any solution for this
Thanks,
Navmen
 
I think this should work

select PhysicalFile, sum(Size_KB/1048576) as size
from(
select distinct PhysicalFile, Size_KB/1048576 from STH_SQLDBSIZE)
group by PhysicalFile

Ian
 
Ian,

When I run this query I got the message :

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'group'.\

When I remove Group By I got the message:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.

Thanks,

Navmen
 
Sorry I work in both Oracle and MS SQL and I forgot MS SQL insists on aliases for subqueries

select q.PhysicalFile, sum(q.Size_KB/1048576) as size
from(
select distinct PhysicalFile, Size_KB/1048576 from STH_SQLDBSIZE) q
group by q.PhysicalFile

Ian
 
Some message on this query:

Msg 8155, Level 16, State 2, Line 7
No column was specified for column 2 of 'q'.
Msg 207, Level 16, State 1, Line 7
Invalid column name 'Size_KB'.

is a select after From supportd?

Thanks,

Navmen
 
Oops brackets and syntax in wrong place when dividing by 1048576

select q.PhysicalFile, sum(q.Size_MB)as Size_MB
from(
select distinct PhysicalFile, Size_KB/1048576 as Size_MB from STH_SQLDBSIZE) q
group by q.PhysicalFile

Ian

 
Hi Ian,

GREAT Job, I modified it to:

select sum(q.Size_MB)as Size_MB from (select distinct PhysicalFile, Size_KB/1048576 as Size_MB from STH_SQLDBSIZE) q

And got the toital size of all files.

Thanks,

Navmen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top