Welcome Guest, Not a member yet? Register   Sign In
Tricky SQL query
#17

[eluser]uptime[/eluser]
[quote author="ehicks727" date="1219784753"][quote author="uptime" date="1219782902"]Why are you using two different tables?

You could have them all under one table with a parent_id field. if parent_id = 0 it would be considered as a new thread. Otherwise set parent_id to the thread's ID. I think it would make your life a little easier. Unless you have another reason, do you?[/quote]

Because that wouldn't be a properly normalized table. Actually, it's not normalized right now because the userid is in both tables, but that's not that big of a deal.

If you threw this all in one table, you'd most likely be painting yourself into a corner. It'll bite you in the butt later when you need to perform more complex manipulations or reporting on the data. As much normalization as is reasonable is always a best practice.[/quote]

This is pretty interesting, I really don't see why should I (or anyone else) use more than one table for that.

Why would reports be hard? It's a simple SELECT FROM WHERE statement so all you would need to do is to do something like this:
Code:
WHERE ... AND post_type = 'thread'
Or like that:
Code:
WHERE ... AND parent_id = '0'

Is there anyone else here thinks that this is not the right way? I would love to hear more about it, seriously.


Messages In This Thread
Tricky SQL query - by El Forum - 08-26-2008, 03:38 AM
Tricky SQL query - by El Forum - 08-26-2008, 04:18 AM
Tricky SQL query - by El Forum - 08-26-2008, 04:27 AM
Tricky SQL query - by El Forum - 08-26-2008, 05:08 AM
Tricky SQL query - by El Forum - 08-26-2008, 05:31 AM
Tricky SQL query - by El Forum - 08-26-2008, 07:44 AM
Tricky SQL query - by El Forum - 08-26-2008, 07:48 AM
Tricky SQL query - by El Forum - 08-26-2008, 08:06 AM
Tricky SQL query - by El Forum - 08-26-2008, 08:32 AM
Tricky SQL query - by El Forum - 08-26-2008, 08:49 AM
Tricky SQL query - by El Forum - 08-26-2008, 08:54 AM
Tricky SQL query - by El Forum - 08-26-2008, 09:09 AM
Tricky SQL query - by El Forum - 08-26-2008, 09:22 AM
Tricky SQL query - by El Forum - 08-26-2008, 09:35 AM
Tricky SQL query - by El Forum - 08-26-2008, 10:05 AM
Tricky SQL query - by El Forum - 08-27-2008, 02:03 AM
Tricky SQL query - by El Forum - 08-27-2008, 08:25 AM
Tricky SQL query - by El Forum - 08-27-2008, 08:28 AM
Tricky SQL query - by El Forum - 08-27-2008, 08:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB