World Populations SQL Practice help

https://www.codecademy.com/practice/projects/world-populations-sql-practice-ii

Does anyone know how to make git bash read a file stored on your computer ??

We are encouraged to complete this task outside of the codecademy in-browser terminal.

I downloaded git bash as per the instructions provided in the exercise and managed to get it to run SQLite3, however I am unable to get it to read the database file provided. It accepts that I have opened the file but seems incapable of reading the tables stored within.

Any help would be massively appreciated

Ok if your sqlite is installed:

  • make sure you are in the same directory as your sqlite file (you can check by typing ls)
  • open file with a command like sqlite3 data.sqlite (replace data.sqlite with the filename)
  • you can type .schema; to view your schema, if the file doesn’t have any tables, you have to create them.
  • you can now query and run operations on your tables!

E.g:

SELECT * FROM my_favorite_table;

If at any time you are doubtful of the commands at your disposition, you can type .help;

Welcome to the forums :slight_smile:

2 Likes

This is most likely the problem. If you are not in the same directory as your database file and you write sqlite3 [name of your file here] without specifying the path to your file, then SQLite will create a new database file in that directory with the name you provided.

So if your file (e.g., populations.db) is in a folder called codecademy, if you open Git Bash to the Desktop and say sqlite3 populations.db, you will create a new file called populations.db on the Desktop rather than opening the one in the codecademy folder.

1 Like

Hi, thank you so much for replying! When I typed

into the git bash terminal, it came up with the contents of the file that I was trying to open - I named the file ‘database.sql’

$ ls
db.sqlite  population_queries.sql

I’m sorry if this is a stupid question as I am brand new to coding, but does this mean that the directory is incorrect, and if so how can I go about changing it? Thank you again!

ls lists the contents of the directory you’re in. This way, you can confirm you’re in the right place.

Now you can open db.sqlite with a command like sqlite3 db.sqlite. (If that’s the file you want). Then you can follow the steps outlined above.

You can then interactively input sql commands (don’t forget to use the ; at the end of your sql queries!)

It’s not a stupid question at all! That’s what the forums are for :slight_smile: @ionmihai

It worked! Genuinely thank you so much for your advice! - I’d wasted hours on this trying to figure it out by myself :sweat_smile:

2 Likes

Hey, thank you for replying :slight_smile: - it did turn out to be a problem with the directory as you and @toastedpitabread pointed out :sweat_smile:

2 Likes

Yea never hesitate to ask. I always give myself a one hour rule if it’s something simple. If I still can’t find the way, I ask for help. (Particularly if it’s practical stuff).

For puzzles/concepts I’ll give myself more time to solve it but usually over a period of time. Even solving it brings up another set of questions that I usually bookmark.

1 Like