-
Is this possible? (MySQL)
Hey guys I'm building a restaurant reservation system and I'm stuck. I have a data-grid in which I want to print all the restaurants tables that currently exist and display which ones already have a reservation. I don't know how or if it's possible in a MySQL query. In case the restaurant thing is confusing, I'll use a social networking site as an example:
You can query to get all users
You can query to get all users that are your friend
I want both of those in one. I want to display all the users but indicate which ones are already my friends.
Is this possible in one query? Can I query users that are my friends and get all remaining users?
-
The answer is definitely a yes - but varies greatly but the actual database structure, the fields, how normalised it is, etc.
Assuming a fully normalised database, you would be looking to display all the tables with your query and then start to restrict the query as necessary; a LEFT JOIN would pull rows from, say, the TABLES table (don't call it TABLES - there's plenty of restricted keywords that are allowed in some places and not others! Causes havoc!!) and pull data optionally from the right hand side RESERVATION table - even if one doesn't exist. An INNER JOIN would require data on both side; a LEFT JOIN in conjunction with an IS NULL on the data contained in the right table (i.e., reservation) would be able to tell if there's no reservation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|