query SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjava
    New Member
    • Sep 2009
    • 132

    query SQL

    hello,
    i want to do this query
    Code:
    $sql = "SELECT * FROM `departement_2`,departement_5,departement_8,departement_12,departement_33,departement_15";
    Does anyone have any ideas on what I should do? thanks.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      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:
      Code:
      department_1
      +----+------------+----------+
      | id | date       | whatever |
      +----+------------+----------+
      |  1 | 2013-01-01 |      ... |
      |  2 | 2013-02-01 |      ... |
      |  3 | 2013-03-01 |      ... |
      +----+------------+----------+
      
      department_2
      +----+------------+----------+
      | id | date       | whatever |
      +----+------------+----------+
      |  1 | 2013-01-01 |      ... |
      |  2 | 2013-02-01 |      ... |
      |  3 | 2013-03-01 |      ... |
      +----+------------+----------+
      You should be doing this:
      Code:
      department
      +----+------------+----------+--------+
      | id | date       | whatever | number |
      +----+------------+----------+--------+
      |  1 | 2013-01-01 |      ... |      1 |
      |  2 | 2013-02-01 |      ... |      1 |
      |  3 | 2013-03-01 |      ... |      1 |
      |  4 | 2013-01-01 |      ... |      2 |
      |  5 | 2013-02-01 |      ... |      2 |
      |  6 | 2013-03-01 |      ... |      2 |
      +----+------------+----------+--------+
      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.

      Comment

      Working...