User
user_id
name
city
UserHistory
user_id
date
action
Your SQL should be compatible with MySQL 4.0. Please avoid using subqueries.
1. Given the tables above, write an SQL query that returns the name, city and most recent date for any user that has logged in over the last 30 days (you can tell a user has logged in if the action field in UserHistory is set to “logged_on”). For example, every time a user logs in a new row is inserted into the UserHistory table with user_id, current date and action (where action = ‘logged_on”).
2. Given the tables above, write an SQL query to determine which user_ids in the User table are not contained in the UserHistory table (assume the UserHistory table has a subset of the user_ids in User table). Do not use the SQL MINUS statement. Note: the UserHistory table can have multiple entries for each user_id.
Thanks Sonu