473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1310
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

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

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.