zulusam zulusam - 3 years ago 77
SQL Question

Do these SQL queries make sense for the given tables?

enter image description here

Give the following two SQL tables I want to run two queries (venue_id is a foreign key with id from the venues table):

SELECT venues.name FROM venues INNER JOIN users ON venues.venue_id = users.venue_id WHERE users.id = {param}


To return the venue name associated with the user_id that was passed in

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time > CURRENT_TIMESTAMP


To return all the current users with a given venue_id where the expiration_time is after the current time.

Do both these queries do what I expect them to do?

Thanks!

Answer Source

SELECT venues.name FROM venues INNER JOIN users ON venues.id = users.venue_id WHERE users.id = {param}

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time > CURRENT_TIMESTAMP

Both queries should be doing what you expect them to do

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download