Questions tagged [sql]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

PSET7 Movies - SQL.13 , how come I have to use the same JOIN lines again? Aren't the tables already joined?

SELECT name FROM people JOIN stars ON stars.person_id = people.id JOIN movies on stars.movie_id = movies.id WHERE movies.id = (SELECT movies.id WHERE stars.person_id = (SELECT id FROM people WHERE ...
user avatar
0 votes
0 answers
6 views

PSET 9: Should I use a separate table for symbols?

Symbols will repeat themselves, since different users can buy shares from the same company, so when creating the portfolio table to store data related to the purchase of shares, I thought I could ...
user avatar
0 votes
0 answers
22 views

finance problem 112.00 (timebound)

:( buy handles valid purchase Cause expected to find "112.00" in page, but it wasn't found Log sending GET request to /signin sending POST request to /login sending POST request to /buy ...
user avatar
0 votes
0 answers
9 views

CS50 library on Google Cloud Platform: Is it possible to handle .db files with CS50?

the CS50 library provides a very simple syntax to use SQL queries for database manipulation. However, when I try to deploy my final project on Google Cloud Platform (GCP), this line of code: db = SQL(&...
user avatar
0 votes
1 answer
62 views

ValueError: UNIQUE constraint failed: on finance pset9, could someone point me in the right direction on which values should be UNIQUE from my table?

Could someone help me figure out which values should I define as UNIQUE? I'm getting the ValueError: UNIQUE constraint failed: compras.id beacuase of the way I created my table for keeping tab of who ...
user avatar
0 votes
1 answer
25 views

CS50 PSET7 Movies "query did not return results" 12.sql

First timer asking on Stack Exchange. I have a SQL query that returns 6 results in the terminal but does not work with check50 resulting in "Query did not return any results" I read in a ...
user avatar
0 votes
1 answer
30 views

PSET7/SQL Any clues as to why my logic isn't working? (13.sql)

This very nested query is to return names of all the actors that performed on a Kevin Bacon film. Instead it's returning nothing, any ideas are appreciated! Note: I'm yet to implement the part that ...
user avatar
0 votes
1 answer
78 views

SQL QUERY MOVIES.DB

I have written the query for 6.sql but it does not work. SELECT AVG(rating) FROM ratings WHERE movie_id = (SELECT id FROM movies WHERE year = 2012); I can do this by using JOIN SELECT AVG(rating) ...
user avatar
  • 72
0 votes
1 answer
512 views

Pset 7 Fiftyville

I am quite sure about my answers but check50 keeps saying its incorrect. Im not sure if I am giving the answers in the correct way. For ex. The thief escaped to Heathrow(I think)/ London but I am not ...
user avatar
  • 7
0 votes
0 answers
15 views

Why am I getting the "Too many statements at once" error? CS50 Final project

I am trying to make a recipe blogging platform, but whenever I pass in values to the database, it gives me a runtime error. The problem is with the 'text' column, as whenever there is a newline in the ...
user avatar
  • 1
0 votes
1 answer
231 views

PSET 9 Finance index.html issue with displaying table results with html

I'm currently on CS50 PSET 9 Finance and stuck on the index.html portion of the assignment. This is my code from assignment.py: @app.route("/") @login_required def index(): stocks = db....
user avatar
0 votes
1 answer
17 views

How do we delete existing flight in sqlite via Django?

In the notes for the SQLITE section, week 3, https://cs50.harvard.edu/web/2020/notes/4/#:~:text=delete%20your%20existing%20flight%20from%20New%20York%20to%20London It states: Every time we make ...
user avatar
0 votes
1 answer
90 views

Week 9 - I need a help about UNIQUE constraint

I am solving the week 9 problem using python. And I am interested in knowing how to deal with the error below using the if and elif? For example: rows = db.execute("SELECT username FROM users ...
user avatar
0 votes
0 answers
249 views

Sqlite3 ProgrammingError in Python (Flask, helper.py file)

I am currently working on my final project, a web application using flask, SQL and javascript. I came across this issue: `sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Cannot operate on ...
user avatar
  • 1
0 votes
1 answer
571 views

pset7 Fifty Ville // not sure how to get the intersect of cases to find the thief

I am currently doing pset7 and I have found most of the clues of who it is but the problem is that I need to use the intersect sql function to find the common name of the thief but I am not sure how. ...
user avatar
  • 17
0 votes
1 answer
185 views

CS50 SQL Library use outside of CS50 IDE

I am trying to create a SQlite database following Dr Malan's class example. The difference is that I am doing it outside of the CS50 IDE. For some reason the below code does actually create the .db ...
user avatar
  • 1
0 votes
1 answer
76 views

DIFFERENCE BETWEEN TWO SQL CODES

I wrote these two codes for SQL pset7 but I'm getting different answers. Can anybody tell me the cause of the difference? SELECT COUNT(title) FROM movies WHERE id = (SELECT movie_id FROM ratings WHERE ...
user avatar
0 votes
1 answer
139 views

How to use a PostgreSQL database using python CS50 library's SQL function?

I wanted to use the CS50 library's SQL function for interacting with a PostgreSQL database. I have installed PostgreSQL on my computer and removed the need for passwords by modifying the .../Program ...
user avatar
  • 101
0 votes
1 answer
217 views

CS50 finance SELL - Cannot get the code to subtract the stock from the database or index

I have tried a number of versions of this code, except I cannot get it to subtract shares from my ("/") index page it does nothing and shows nothing in the shares column in the transaction ...
user avatar
0 votes
1 answer
11 views

Project: Conditional style for html table

I have a table in html which gets the data from a SQL query in PY. One of the columns in my SQL table is type (tp). I want the html table to show one color for each row of the same type and another ...
user avatar
0 votes
1 answer
70 views

pset 7 houses passes check 50 but shows the names 4 times

I have a really strange problem here: both import and rooster passes every check in check 50, but if I run Rooster the names on every house appear 4 times. I have no clue about why this is happening, ...
user avatar
0 votes
1 answer
130 views

FINANCE: GROUP BY doesn't add up the numbers of shares of the same stock

So in index i'm trying to display a table with all the stocks that the user has bought, one row for each stock, displaying the total number of shares in the user's portfolio along with the total value ...
user avatar
  • 35
0 votes
1 answer
130 views

PSET8 Finance Buy. SQL query not executing

My buy function is crashing at the SQL query where I'm trying to insert data from the transaction into a transactions table. The types of each column are transaction_id(integer, primary key), user_id(...
user avatar
0 votes
1 answer
143 views

CASH NOT UPDATING - FINANCE SELL

so everything I have so far is working except the part where I need to update the cash right after I sell a stock. As you can see in the table below what's happening is that everytime I sell a stock ...
user avatar
  • 5
0 votes
1 answer
640 views

PSET 7 Movies SQL Q9

In 9.sql, write a SQL query to list the names of all people who starred in a movie released in 2004, ordered by birth year. ...Your query should output a table with a single column for the name of ...
user avatar
0 votes
1 answer
114 views

Problem taking a SUM with SQL to python

I am doing Finance and I am fighting with this code... could anyone help me? I want to "select" some data from a sql table and put this value to a variable in python (a specific FLOAT number)...
user avatar
0 votes
1 answer
68 views

PSET 7 HOUSES - Syntax error on case function

I'm trying to select the first name and last name and ONLY select the middle name when there is one. The logic of my query makes sense. Every time I am extracting the first name, last name, and birth. ...
user avatar
  • 5
0 votes
1 answer
282 views

pset7 Q10 Weird Result

The challenge is apparently straightforward: write an SQL query to list the names of all people who have directed a movie that received a rating of at least 9.0. To get from names (which lives in the '...
user avatar
0 votes
0 answers
21 views

Final Project: dynamic page creation to show just 10 SQL entries per page

I'm developing a web-page for my CS50's Final Project for contacting japanese students around Argentina. The only official japanese exam takes place in Buenos Aires, and there are no many good places ...
user avatar
0 votes
1 answer
123 views

Finance - Missing Value For Placeholder

As far as I can tell, I have the value set - username = username. Am I missing something stupid here? Code: @app.route("/register", methods=["GET", "POST"]) def ...
user avatar
0 votes
1 answer
250 views

Pset7 (Movies) 12.sql: Table outputs 96 rows rather than 5 rows

I've been stuck on this for quite some time and did a lot of research on the AND operator in SQL, but no matter how many variations I try I cannot get my table to output just 6 rows, with each row ...
user avatar
0 votes
1 answer
221 views

PSET 7 - 6.sql, terminal just hangs

PSET 7 for 6.sql, Terminal just hangs when I execute it. Can anyone tell me why this wouldn't work? I've tried every variation I could think of (and several I found online) for this and none of them ...
user avatar
0 votes
1 answer
127 views

Pset7 Movies Q12: I don't get what's wrong

I can't figure out why my pset7 movies Q12 code isn't working. Can anyone tell me why? Here is my code: SELECT DISTINCT title FROM movies, stars, people WHERE movie_id IN (SELECT movie_id FROM stars ...
user avatar
  • 1
0 votes
1 answer
87 views

Can't import books.csv using import.py

I'm on a project1, here is the link to it: https://docs.cs50.net/ocw/web/projects/1/project1.html I've successfully made a Table books using my Python script, however when I try to import the "books....
user avatar
0 votes
1 answer
174 views

CHECK50 Bug in pset7: movies SQL

I have been banging my head on this for an hour and half. Finally finished the pset, uploaded it. Check 50 says: Now, both cs50 ide and DB browser return the correct results, and number of lines for ...
user avatar
1 vote
1 answer
154 views

Finance: Ensuring no duplicate usernames

I've implemented the following code in my "/register" route: def register(): """Register user""" if request.method == "GET": return render_template("register.html") else: #...
user avatar
  • 13
0 votes
1 answer
314 views

PSET7 Movies Q8 - Why these queries return different results?

I'm working on pset7 movies problem of the CS50 course and I have a question regarding 8.sql, which asks to write a SQL query to list the names of all people who starred in Toy Story. To my ...
user avatar
  • 3
0 votes
1 answer
404 views

Pset 7 Movies - 13.sql "Error When Executing Query - Too Many Statements at Once"

I'm working on Pset 7 "Movies" and check50 shows an error for 13.sql (list of Kevin Bacon's co-stars) when I submit my code despite running successfully in the IDE. The exact error message is Error ...
user avatar
  • 3
0 votes
1 answer
82 views

Pset7 Houses, what does my error message mean?

Whenever I run my code, I get a strange error message because of my code. It is because of my SQL code, but I followed all of the instructions, and even tried some other SQL code, which worked ...
user avatar
  • 2
0 votes
0 answers
32 views

Deleting SQL dynamically with Flask

I want to delete a specific row in my database but I don't know how to do it. On my HTML I have this: <div class="cases"> {% for row in rows %} <div class="card border-success mb-...
user avatar
0 votes
0 answers
2k views

(psycopg2.errors.UndefinedTable) relation "users" does not exist

when i try to load up regster.html i get this error "sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "users" does not exist LINE 1: INSERT INTO users(username,password) ...
user avatar
0 votes
1 answer
15 views

Difference between { var } vs :var as placeholder - SQL, Postgre

I was wondering if it's a good idea to use { var } in place of :var as placeholder? This is what I see in CS50 notes: flight = db.execute("SELECT * FROM flights WHERE id = :id", {"id": flight_id})....
user avatar
0 votes
0 answers
106 views

How to ensure proper database url in environment variable?

I am trying to run the code from lecture3 and I am having trouble ensuring the database url is properly set using the environment variable. Here's the code: db_url = 'postgresql+psycopg2://{username}:...
user avatar
  • 101
0 votes
1 answer
570 views

pset7/movies/13.sql: exclude Kevin Bacon from the resulting list

In pset7/movies, I want to dynamically exclude Kevin Bacon from the resulting list (e.g. not specifically mentioning his name with NOT or EXCEPT or copying and pasting code that calculates his ID, so ...
user avatar
0 votes
1 answer
129 views

CS50w Project1: Trouble posting reviews (Row Proxy error - how to ensure a tuple)

The last bit I am struggling with on Project1 is posting a rating and review. I continually get sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'RowProxy' [SQL: INSERT ...
user avatar
  • 63
1 vote
0 answers
18 views

Why doesn't IDE50 highlight the "IN" keyword in SQL?

Highlighting works well with all other keywords I tried, this is confusing to people who might think (like me, originally) that the keyword is wrong/inexistent...
user avatar
0 votes
1 answer
134 views

CS50 Web Programming: Lecture 3 (SQL)- import.py won't work for me

I'm trying to run the same code for import.py from the lecture, but am running into trouble. import.py: import csv import os from sqlalchemy import create_engine from sqlalchemy.orm import ...
user avatar
  • 1
1 vote
2 answers
4k views

PSET7 Movies Q9: Why is my number of rows generated different from what the assignment requires?

Here are the parameters for running a SQL query in the file 9.sql: In 9.sql, write a SQL query to list the names of all people who starred in a movie released in 2004, ordered by birth year. ...
user avatar
0 votes
3 answers
4k views

PSET7 Movies - Q13.SQL How to NOT include 'Kevin Bacon' in List of Actors that have starred in movies with 'Kevin Bacon

I was able to determine the list of actors that have been in movies with 'Kevin Bacon' and get rid of the duplicates with DISTINCT; however, I cannot figure out how to exclude 'Kevin Bacon' from the ...
user avatar
0 votes
1 answer
256 views

pset7 houses ISNULL function

I want to replace all NULL value by nothing('') in an output query. Note: I don't want to replace the NULL by nothing in the table. SELECT row1, row2, row3 ISNULL(row1,'') AS row1 FROM table output ...
user avatar
  • 53