This is a discussion on Return Extraneous Info In 1 Query, Or Use 2 Queries? within the MySQL Database forums, part of the Database Forums category; Hey there This is a hypothetical question... Let's say I'm querying my database for info about a specific ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey there
This is a hypothetical question... Let's say I'm querying my database for info about a specific company (their name and address) and files associated with that company (stored in another table with CompanyID as the foreign key). For this example, let's say there are 12 files associated with this company. Now, I could get all the information I want in in one query, something like: "SELECT f.FileID,f.FileName,c.CompanyName,c.CompanyID,c.Ad dress FROM Files f JOIN Companies c ON (f.CompanyID=c.CompanyID) WHERE f.CompanyID=14" That would give me everything I wanted, plus extra info: the company details are returned 12 times (in each row about the file) Alternatively, I could get my desired information in two queries: one for company details, another for the files associated with it. Which is "better", or, "less expensive"? Generally I've always thought one query is almost always better than two, but at some point I imagine returning a lot of extraneous data becomes expensive in itself... Thought and opinions appreciated! |