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 PostWhat database are you using? I ran something similar to the above in MySQL and didn't get the error. When I used to work with Oracle and MS-Access databases I remember getting errors like that.
If you are using MySQL as your database, do you by any chance have …
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.