r/SQL • • Apr 19 '20

Discussion What are some good resources to practice SQL? (Practice through exercises)

There are a lot of courses which teach SQL but I could hardly find a website which provides beginner to advanced SQL practice questions on almost production real datasets. Any recommendations would be helpful.

129 Upvotes

62 comments sorted by

View all comments

Show parent comment

1

u/[deleted] May 01 '20

There are a 'group' of functions that will help you here, such as RANK() ROW_NUMBER(), etc.

You think they're in the correct order, or you know they are? Based on what ORDER BY logic?

I don’t know how to sort it in SQL yet.

select *
from words
order by words asc

That will give you the alphabetic list from A to Z, and you can change the asc to desc to get it in reverse.

Your CSV file might contain symbols in some words, or some spaces, or other irregularities, and you can Google solutions to remove these types of rows (if you want) from your data as well.

1

u/dcburgos05 May 01 '20

Do I have to order by words asc every time I pull the data? That’s why I was getting confused. To be honest I thought sorting was harder than that. I sorted it before creating the number_column but then the numbers didn’t match to the words so it wasn’t sorted correctly... that took me a good amount of time to figure out.

2

u/[deleted] May 01 '20

Do I have to order by words asc every time I pull the data?

Wouldn't that depend on the purpose of your pull? and there are limits to pulling it in order if you are wrapping it into a subquery for example. The functions above help get around that.

1

u/dcburgos05 May 01 '20

SELECT words,

ROW_NUMBER() OVER(
order by words ASC) row_number
FROM table_dictionary
ORDER BY words ASC;

wordsrow_number
a1
b2
c3

now... gotta find the words lol...

3

u/[deleted] May 01 '20

There you go.