Hi all, I hope you are well. I have a very quick question for you please. I have a table with x rows and y columns. I need to select the top 100 rows ordered by col2 for eg. Further, I need to select only one row for a particular column value. for example, I need to select top 100 rows, order by col2 but grab only the first row where col1 is duplicated(in that order). Iam no SQL pro so is there any advice or pointers you guys could give? Thanks.
thedrones 0 Newbie Poster
Recommended Answers
Jump to PostFor this you need ORDER BY (to order the rows) and GROUP BY (to get the distinct record). e.g.
SELECT * FROM table_name GROUP BY col1 ORDER BY col2 DESC LIMIT 100
Choose one of the following in your query according to your requirement. In query I …
Jump to PostI thought you could also use "DISTINCT" to specify no duplicates in a records.
DISTINCT only works when you are SELECTing only one column and needed that column DISTINCT. But if you have multiple columns in SELECT statement but want only one of them to be distinct then you must …
All 8 Replies
mwasif 10 Posting Whiz
thedrones 0 Newbie Poster
d5e5 109 Master Poster
teedoff 3 Posting Pro
mwasif 10 Posting Whiz
teedoff 3 Posting Pro

1stDAN

1stDAN
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.