question

Ryan 1 avatar image
Ryan 1 asked

Returning Data from 1 of 4 tables

I am relatively new to using SQL, and have come up against a problem (perhaps it is mis-use on my part, or maybe there is a work around). Here is my scenario...

I have five tables.
Table 1: A listing of documents Table 2-5: Reviews of the documents listed in the above table

Tables 2-5 are linked by a field docid. If the tables 2-5 contain the matching docid, then the review is returned from that table. Something to note is that a document will only be listed as 1 document type (and cannot be changed).

Currently I am using 4 "LEFT JOIN " statements, then using PHP to see which table returned a match.

This is creating ridiculously slow load times. If I break it apart, each one seems to load more efficiently.

My other thought is to combine the 4 tables into one (but the fields used in each are all unique, with a few exceptions, so I didn't think this would be a good solution).

Any help that can be offered would be greatly appreciated.

Thanks!

joins
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kristen avatar image Kristen ♦ commented ·
This is likely to require some to-ing and fro-ing, better to register on SQL Team Forums and re-ask the question there (Forum better suited to discussion than this Ask Question section fo SQL Team). www.sqlteam.com/forums/
0 Likes 0 ·

1 Answer

·
Scot Hauder avatar image
Scot Hauder answered

Can you post the table and index scripts. Unless the tables are huge I'm guessing you are missing some indexes. Are you using SQL Server or MySQL? While the db is still small this would be a good time to normalize it or combine them as you stated

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.