I have one table in my db that looks like this:
| userid | username | dateloggedin | etc
| 1 | Joebloggs | 27-03-16 | etc
| 2 | Nathanbloggs| 27-03-16 | etc
and a logging table that looks like this:
| eventtype | userid | eventdate | etc
| loggedin | 1 | 27-03-16 | etc
| loggedout | 1 | 27-03-16 | etc
When I display the entries from the eventlog I want to also display the username, not just the userid.
What's the best practice here, should I store the username in both the eventlog table and the users table so I can access all data in a single query? Or should I use the userid to cross reference the other table and get the username from there, only storing it once?
Given that I am planning for volumes I'm not sure which route is best - more processing time from switching between queries and arrays, or more storage space used by duplicating data.
http://www.tutorialspoint.com/sql/sql-using-joins.htm
This link explains the sql JOINS syntax quite well, thanks!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.