469,927 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

query SQL

132 100+
hello,
i want to do this query
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM `departement_2`,departement_5,departement_8,departement_12,departement_33,departement_15";
  2.  
Does anyone have any ideas on what I should do? thanks.
Jul 2 '13 #1
2 1174
Rabbit
12,516 Expert Mod 8TB
You can certainly run that SQL. It's syntactically correct although I have no idea why you would want to have so many cartesian joins. It's going to eat up a lot of resources. But there's nothing in the syntax to prevent you from running that SQL.
Jul 2 '13 #2
Atli
5,058 Expert 4TB
The names of those tables suggest a fairly big problem with your design. Whenever you start putting actual data into the structure of the database, that should be a huge red flag. - In your case, you have "department_N", where N is a number that I'm guessing represents an ID for the department who's data it stores?

Generally you would put that data into a table, rather than create multiple tables wit the data in the table name. So instead of doing something like this:
Expand|Select|Wrap|Line Numbers
  1. department_1
  2. +----+------------+----------+
  3. | id | date       | whatever |
  4. +----+------------+----------+
  5. |  1 | 2013-01-01 |      ... |
  6. |  2 | 2013-02-01 |      ... |
  7. |  3 | 2013-03-01 |      ... |
  8. +----+------------+----------+
  9.  
  10. department_2
  11. +----+------------+----------+
  12. | id | date       | whatever |
  13. +----+------------+----------+
  14. |  1 | 2013-01-01 |      ... |
  15. |  2 | 2013-02-01 |      ... |
  16. |  3 | 2013-03-01 |      ... |
  17. +----+------------+----------+
  18.  
You should be doing this:
Expand|Select|Wrap|Line Numbers
  1. department
  2. +----+------------+----------+--------+
  3. | id | date       | whatever | number |
  4. +----+------------+----------+--------+
  5. |  1 | 2013-01-01 |      ... |      1 |
  6. |  2 | 2013-02-01 |      ... |      1 |
  7. |  3 | 2013-03-01 |      ... |      1 |
  8. |  4 | 2013-01-01 |      ... |      2 |
  9. |  5 | 2013-02-01 |      ... |      2 |
  10. |  6 | 2013-03-01 |      ... |      2 |
  11. +----+------------+----------+--------+
  12.  
The number there represents the department number the row belongs to.

This makes the data a LOT easier to work with, and makes it possible to add as many departments as is needed without having to keep creating new tables.
Jul 4 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by jaysonsch | last post: by
9 posts views Thread by netpurpose | last post: by
3 posts views Thread by Harvey | last post: by
14 posts views Thread by Dave Thomas | last post: by
3 posts views Thread by pbd22 | last post: by
4 posts views Thread by Stan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.