Possible Duplicate:
MYSQL don’t return duplicate rows
I know this question has been asked before, but I haven’t been able to see any solutions that worked with my situation. A typical SQL statement looks like this:
SELECT Hostname,Site,Rack FROM hardwaredb WHERE Hostname LIKE '%$hostval%'
$hostval is a powershell variable that gets replaced with a system’s name. So if I had a system named OldGlory117, the statement would look like this:
SELECT Hostname,Site,Rack FROM hardwaredb WHERE Hostname LIKE '%OldGlory117%'
Because of other columns, some rows are duplicated, and there are duplicate hostnames in the database. So the above query might return:
OldGlory117 USA Rack1
OldGlory117 USA Rack1
OldGlory117 USA Rack1
This is problematic when I’m not looking for the column that causes the duplicates. Is there any way to return only rows that have unique values for hostname? What if I’m not specifying hostname in the WHERE statement? Ex:
SELECT Hostname,Site,Rack FROM hardwaredb WHERE Rack LIKE '%Rack1%'
Thanks!
Is it possible for you to use a GROUP BY?