![]() |
Displaying a table column in addition to query results
Hi Everyone,
I am running the following MySQL query: [code] SELECT COUNT(*), OldCompanyName, NewCompanyName FROM moortown5 GROUP BY OldCompanyName, NewCompanyName HAVING COUNT(*)>1; [code] This successfully returns matches and partial matches from the required column. My problem is this. I want to display a column called 'Records' along with the results so that I know which table row the results belong to. Can anyone help? Thanks very much in advance.:confused: I believe I need to display the 'Records' column by default with all query results somehow? |
If you want to be able to identify the table row, then *YOU* need to provide a field in the table that will do so. Records in relational databases (of which MySQL is one) do *NOT* have record numbers automatically attached to them.
And easy way to add such a number would be Code:
ALTER TABLE moortown5 ADD recordID INT AUTO_INCREMENT PRIMARY KEYCode:
SELECT COUNT(*), recordID, OldCompanyName, NewCompanyName FROM moortown5I assume that you want to get a list of *ALL* the duplicated recordid's no? There are a couple of ways to do it, but this may be the best: Code:
SELECT T.recordID, T.OldCompanyName, T.NewCompanyName |
Another way is this:
Code:
SELECT DISTINCT T.recordID, T.OldCompanyName, T.NewCompanyName |
Thanks ever so much for your assistance, I'm all sorted now. Much appreciated.
|
| All times are GMT +1. The time now is 01:23 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.