By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,406 Members | 2,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,406 IT Pros & Developers. It's quick & easy.

query SQL

100+
P: 132
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
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
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
Expert 5K+
P: 5,058
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.