Bluehost.com Web Hosting $6.95

Return Extraneous Info In 1 Query, Or Use 2 Queries?

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


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-21-2007
Good Man
 
Posts: n/a
Default Return Extraneous Info In 1 Query, Or Use 2 Queries?

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!



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0