Query results isn't working - Is it my code incorrect or is it not working

Hi there,

My code for the first project on SQL (create a table) isn’t querying any results. It does show results after the first step, but then after that nothing else comes up. Is my code below correct?

Thanks for the help in advance

CREATE TABLE friends (
id INTEGER
name TEXT
birthday DATE
);

INSERT INTO friends (id, name, birthday)
VALUES (1,'Jane Doe','1990-05-30');

SELECT *
FROM friends;

INSERT INTO friends (id, name, birthday)
VALUES (2,'John Powers','1990-03-20');

INSERT INTO friends (id, name, birdthay)
VALUES (3,'Jack Stevens','1992-04-21');

UPDATE friends
SET name = 'Jane Smith'
WHERE id = 1;

ALTER TABLE friends
ADD COLUMN = email TEXT;

UPDATE friends
SET email = '[email protected]'
WHERE id = 1;

UPDATE friends
SET email = '[email protected]'
WHERE id = 2;

UPDATE friends
SET email = '[email protected]'
WHERE id = 3;

DELETE FROM friends
WHERE id = 1;

SELECT *
FROM friends;

```````

Did you try to comment out each chunk of code to see what printed?

to comment out in SQL, add: /* at the beginning of what you want to comment out and then add: */ at the end of what you want commented out.

2 Likes

Hello,

Your first issue is that the table never gets created because you are missing commas in your CREATE TABLE

You also have a typo with one of your column names in one of your INSERT statements.

Also, double check your ALTER TABLE because you have an extra = in there.

Rather than just give you the answer as to what’s wrong, I find it best to have you figure it out first. :slight_smile:
When de-bugging code, it’s sometimes good to read it from the bottom up too. I do that and it gives you a different perspective.
Same goes for commenting out code and seeing what prints and what doesn’t. (b/c you’re not given any error messages in the LE for SQL here).

2 Likes

Firstly, thanks for your advice about debugging. I’ll take it to heart!

For your second point, I didn’t try to comment out each code, but I’ll give it a go.

2 Likes

Hi there,

Thank you for your feedback.

I’ll look over my code and make sure there aren’t any mistakes this time around.

Thanks

Were you able to fix it? I am having the same problem and I can’t figure out how to apply those responses. Any success?

Without some idea of what you did and what you expected to happen it might be hard to assist. The earlier advice about trying this line by line to see what does/doesn’t work is a good place to start.

If you’re still stuck have a nosey through the following FAQ which details how to set up a question for the forums for your best chance of getting some help.

2 Likes

I had the same problem, so I hit “reset workspace” and tried again and it worked!

1 Like