Hi,
Please consider this data/table consisting of 3 Columns with the 2nd Column having Duplicate Values (Book Titles here) :
Note:SELECT * FROM Books
Code:
Book_ID Book_Title Tags
1 C Pointers
2 VB Programming
3 C DS
4 Java Multi Threading
5 PHP Website
6 SQL SQL
7 SQL SQL
8 C++ OOPs
9 Oracle RDBMS
10 VB Software Development
Let's Sort the Data/Table on the 2nd Column i.e. book_title:
Code:
Book_ID Book_Title Tags
1 C Pointers
3 C DS
8 C++ OOPs
4 Java Multi Threading
9 Oracle RDBMS
5 PHP Website
6 SQL SQL
7 SQL SQL
2 VB Programming
10 VB Software Development
We see that Book_ID: 3, 7, and 10 above have duplicated values in their respective Book_Title fields.
In the result/output we do want all the 3 Columns (or all the columns of the table) with the condition that if any Book_Title is coming again down the list then only the first one needs to be
SELECTed. In other words, we want to exclude duplicate book titles irrespective of what values the other corresponding columns may have.
So, the desired output should look like as follows:
Code:
Book_ID Book_Title Tags
1 C Pointers
8 C++ OOPs
4 Java Multi Threading
9 Oracle RDBMS
5 PHP Website
6 SQL SQL
2 VB Programming
Please Note: In the first table above, the Book IDs 6 and 7 show identical records. But that is not the case with the other records. So, whether 2 or more records are identical or not (DISTINCTROW, in MS Access), we are concerned about a specific column's values and want them to be UNIQUE in our Result/Output. Kind of
GROUP BY Query but that would not help us
display all the fields/columns.
Do we need some Sub-Query or Join here? Any ideas, gurus?