In Pset7, history, I'm trying to sort the data by date, I tried ORDER BY but it gave me"syntax error near when"(when is the date column name, and its data type is: DATETIME) .. what is the right way to do it??

rows=db.execute("SELECT * FROM portfolio WHERE id=:id AND howMany  >= 0 UNION SELECT * FROM sell WHERE id=:idd ORDER BY when "
,id=session["user_id"], idd=session["user_id"])
  • If you want data from two tables at once, wouldn't it be better to JOIN sell ON sell.id=portfolio.id (if this makes sense at all)? The table layout looks quite odd, usually you'd prefix foreign keys, like user_id, and use id for a primary key of that table. – Blauelf Sep 25 '17 at 16:49
  • Alright, Thank you very much! in this case, I'll have to add a column in the portfolio table for the foreign key, and link that to user_id in sell table, right? – Raw Sep 28 '17 at 5:25
  • it's not related to the original question, but may I ask, How can I add images to cs50 cloud, to use them in my project (for backgrounds and icons)? – Raw Sep 28 '17 at 5:30
  • You could upload ("File"->"Upload Local Files...") them into the static directory. The template layout.html for example includes styles.css using some Jinja within the HTML link element: <link href="{{ url_for('static', filename='styles.css') }}" rel="stylesheet"/> (this is replaced with /static/styles.css on runtime, you could also use a static link, doesn't matter as long as paths don't change) – Blauelf Sep 28 '17 at 14:48
  • Thank you for your help! – Raw Sep 29 '17 at 9:26

You must log in to answer this question.

Browse other questions tagged .