Jump to content

Joining tables


arunpatal

Recommended Posts

Hi, i have 4 tables and three of them have same fields

 

T1 = CSS

T2 = PHP

T3 = HTML

 

T4 = subcat_table

 

now i am sending one value via get link

 

page.php?sub_id=14

 

now i want to display all data from T1, T2, T3 which have sub_id value = 14.

 

ofcourse T1, T2, T3 have sub_id field.

Link to comment
Share on other sites

 


now i want to display all data from T1, T2, T3 which have sub_id value = 14.

 

If the tables have different columns then run four queries.

You are fetching three different types of data and I'm guessing you also want to know and show which data is CSS, which is PHP and which is HTML and that's just easier with separate queries.

 

A UNION is possible, if the tables are identical, but the I'd advise to doe something like:

SELECT col1, col2, col3, 'CSS' AS data_type FROM css_table

UNION ALL

SELECT col1, col2, col3, 'PHP' FROM php_table

UNION ALL

SELECT col1, col2, col3, 'HTML' FROM html_table

 
so you can use the new virtual field 'data_type' in your resultset to see which is which. Otherwise you'l use CSS asif it is PHP and that just weird.
 
Oh, and in that case I'd also like to know why there are sperate tables, that would only serve a purpose if the tables contain millions of records.
Link to comment
Share on other sites

 


So you're talking about tens of millions then?

 

Or thousands of large records, or heavily indexed records, or a server with slow disks, or the database system has no per-record security.

 

Granted, it is usually only the really large tables that need partitioning, but sheer volume is not the only reason to do it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.