Questions tagged [sql]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
20 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 ...
0
votes
0answers
9 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 ...
0
votes
1answer
75 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....
0
votes
1answer
14 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 ...
0
votes
1answer
41 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 ...
0
votes
0answers
177 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 ...
0
votes
1answer
472 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. ...
0
votes
1answer
98 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 ...
0
votes
1answer
67 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 ...
0
votes
1answer
93 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 ...
0
votes
1answer
146 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 ...
0
votes
1answer
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 ...
0
votes
1answer
64 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, ...
0
votes
1answer
90 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 ...
0
votes
1answer
104 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(...
0
votes
1answer
104 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 ...
0
votes
1answer
521 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 ...
0
votes
1answer
68 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)...
0
votes
1answer
66 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. ...
0
votes
1answer
226 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 '...
0
votes
0answers
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 ...
0
votes
1answer
89 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 ...
0
votes
1answer
220 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 ...
0
votes
1answer
202 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 ...
0
votes
1answer
109 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 ...
0
votes
1answer
86 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....
0
votes
1answer
156 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 ...
1
vote
1answer
108 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: #...
0
votes
1answer
284 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 ...
0
votes
1answer
316 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 ...
0
votes
1answer
76 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 ...
0
votes
0answers
25 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-...
0
votes
0answers
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) ...
0
votes
1answer
14 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})....
0
votes
0answers
71 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}:...
0
votes
1answer
500 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 ...
0
votes
1answer
110 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 ...
1
vote
0answers
17 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...
0
votes
1answer
130 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 ...
1
vote
2answers
3k 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. ...
0
votes
3answers
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 ...
0
votes
1answer
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 ...
0
votes
1answer
492 views

pset7 houses: dict to SQL

I need to pass a python dict to a database with SQL. one of my dicts is: print(student[1]) {'first': 'Adrian', 'house': 'Slytherin', 'birth': '1977', 'middle': 'NULL', 'last': 'Pucey'} I want to ...
0
votes
1answer
381 views

PSET7 cs50 import SQL

I'm looking for the documentation about the module CS50 SQL imported in python. Where can I find all the commands ? Thanks in advance,
0
votes
1answer
36 views

Final project question and Hardware for a SQL server

Hello Dear Coders, I'm in charge of a radiology center (Xray imaging) and we need a cross server system to get patient datas with images. For the CS50 final exam I wish to build a "test" server for ...
0
votes
0answers
94 views

SQL Query returning nothing

For my final project, I query my database for a the ID of a city whose Name I already have. However, SQL returns no such city even when there is one. Code (Line with error is surrounded by stars): ...
0
votes
1answer
172 views

Finance: Can not Update and Insert to SQL

In my buy function I cant INSERT or UPDATE data in SQL. RuntimeError: (sqlite3.OperationalError) near "ON": syntax error [SQL: INSERT INTO buy (share_name, share_symbol, share_price, shares, id) ...
0
votes
1answer
28 views

Substring SQL Search

I am trying to query the Database for a sub-string, I am substituting a string variable from a form for the query. It is giving me a syntax error. This is the error: LINE 1: SELECT * FROM books ...
1
vote
1answer
80 views

line 541, in sell user_id = current_id coming back as an error, Why? Is it caused by global variables? Thanks

I know my variable names suck. sell application.py @app.route("/sell", methods=["GET", "POST"]) @login_required def sell(): """Sell shares of stock""" current_id = session["user_id_2"] ...
0
votes
1answer
157 views

Why won't DELETE * FROM in sql work? i Guess I could delete each column individually. Further info below

sell application: total_shares = db_shares[0]["shares"] - int(shares) if total_shares == 0: db.execute("DELETE * FROM stock_info WHERE id = :user_id AND stock_symbol = :...