Answer the question
In order to leave comments, you need to log in
What is the best way to write a SQL query?
I'm trying to make a nice, normally readable SQL query for a database like this:
Tables:
users [id, name] // no more fields needed for this example
users_events [id, timestamp, event_type, event_value, user_id]
users_data [id, timestamp, data_name, data_value , user_id]
Data is added to users_events after each user event. Example event: change of residence.
Looks like:
{
id: 123,
timestamp: '10.03.13',
event_type: 'city',
event_value: 'Moscow',
user_id: '888'
}
{
id:122,
timestamp: , // некая дата
data_name: 'last_name',
data_value: 'Vasechkin', // сначала было старое имя
user_id: 888
}
{
id:123,
timestamp: , // некая дата
data_name: 'last_name',
data_value: 'Pupkin', // потом заменили на новое
user_id: 888
}
{
id:124,
timestamp: , // некая дата
data_name: 'phone',
data_value: '1234567',
user_id: 888
}
{
id:125,
timestamp: , // некая дата
data_name: 'phone',
data_value: '1233214',
user_id: 888
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question