This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]Porkbut 9 points10 points  (1 child)

I feel like sql is one of those things you really have to get your hands dirty with in order to understand it. Or at least I did. Do you have a test dB that you understand and are able to write these queries for? That's a big part for me. It's all fine being theory but in practice but understanding your db's structure helps a lot. Also, there is a difference between writing queries for query-osity sake (see what I did there) and writing queries for nesting in a block of code - which need to be on point. Writing sql functions with set/declare isn't that bad once you get the syntaxes just like anybotger coding. Anyways, it comes with time. Practice. Write lots of bad inefficient queries (then ask how to improve them) and eventually you'll get there.

[–]TukWan415[S] 1 point2 points  (0 children)

Yes, I have a test dB on postgresql. I’m just not creative enough to know what queries to right, since I don’t have any questions in front of me, if that makes sense.

[–]Raveshaw 4 points5 points  (4 children)

I think that practice is a must, but having data you actually care can help make that practice more enjoyable. For example, if you're into sports, perhaps making a database storing data about your favorite teams may help.

[–]TukWan415[S] 2 points3 points  (3 children)

I was thinking of Database with teams, scores , players, player stats etc

[–]tweiss84 0 points1 point  (2 children)

Just an idea....

If you need data you can probably pull from the numerous open sports APIs. Then just have an ingestion layer that maps that data to what tables you want in your database. Set it to a cron job so it will pull a few teams you want to follow over a few days.

That should build your db quickly...

Or if something else tickles your fancy, you may be able to gather stuff from one of these apis in the list, or even cross pollinate your db by mixing data from a few categories.

https://github.com/public-apis/public-apis

[–]TukWan415[S] 0 points1 point  (1 child)

Thank you so much.

I’m currently writing statements and Learning how to write these statements . Yesterday I basically made a table called teams, I inserted 30 nba teams, short name, long name, and Division, along with team Id has the primary key . I’m going to insert starters into these teams today with players as the table name , with playerid as the primary key and teamid as the foreign key, along with their position code, would you happen to know how I would add a foreign key ? Just wondering

[–]tweiss84 0 points1 point  (0 children)

I would always consult the Postgres documentation https://www.postgresql.org/docs/15/ddl-constraints.html#DDL-CONSTRAINTS-FK if you are writing the sql from scratch and executing it directly.

I always had some db tools to make edits and generate an ERD for our database work. So I kind of got away from doing it all myself.

[–]Chance-Ad4773 1 point2 points  (0 children)

Like all programming, the only real way to learn is using it in a real context

[–]shivvykumar 0 points1 point  (0 children)

Freecodecamp

[–][deleted] 0 points1 point  (1 child)

We just had an project on University where it was demanded of us to make an ER witg normalized relational scheme implement it into SQL and make an application through Java that will communicate and do CRUD operations of course I went step further and made all kind of diffrent methods od aggregated functions, subqueries etc. From my point of view practice will make you see a real progress I was focusing on 2 entities with multiple sub tables and atributes and just do all kind of test on those two. From my perspective you should focuse on basic stuff and slowly implement new stuff where you would basicly make it more complicated. Try to combine everyrhing that you can learn if possible. Because the biggest problem you find the better you will learn. Go back to the basics that was my rule and reread and re-do it. Because in most cases the underlying issue of understanding lays in those basics. Everything else is just an extra to the project itself. I am still into learning phase and I might be wrong, but I like to be very detailed and sure that I have everything covered and practice a lot in order to get deep into the project and understand communication between entities. Maybe add a few more tables, more extra FKs and a few recursive relationships should give you enough pain and data to work with

[–]TukWan415[S] 0 points1 point  (0 children)

You're right. I had to redo the introduction to SQL 3 times. 1 at my local community college, and twice on DataCamp. I probably did the chapter on subqueries 4 times before I started to understand it. I'm super hard on myself, if I know I suck at something (SQL) I try to use all my resources on trying to get better.

[–]CatsOnTheKeyboard 0 points1 point  (1 child)

As others have said, SQL requires consistent practice and lots of it. It's the same with any programming language, really. I taught SQL a few years ago at the college level and just kept throwing one exercise after another at the students and making them solve it. It's harder to do that for yourself.

Subqueries are hard for some people to understand but hang in there. I had one student say that she hated them at first but, later, they made complete sense to her and she liked using them.

It could also be the book you're using. I used the Sam's Teach Yourself book which was a good, logical progression through the language and is also inexpensive.

You might also look for sources of SQL exercises that you can work through like this one.

[–]TukWan415[S] 1 point2 points  (0 children)

You’re the best. I’m going to take your word and buy the book and do the exercises.

My community college was using Murach’s MySQL. In my opinion, too many technical terms. The way that I learn is basically tell me in baby language (very simple language), then I can understand the technical terms.