Current location: Hot Scripts Forums » Programming Languages » ASP » tables joins - 3 tables


tables joins - 3 tables

Reply
  #1 (permalink)  
Old 03-17-04, 12:22 PM
lordmerlin lordmerlin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: South Africa
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
tables joins - 3 tables

Ok, I got three tables, company, comments and old_company.

In company are all the current companies, in old_company are companies who
have been suspended, and in comment, clients can make comments about the
companies, regardless if they are current or suspended companies.

I currently display all the comments on a page, but now I want to put an
icon next to the companies who are still with us, and another tick with the
suspended companies, making a clean indication as to which is which.

I tried the following statement, and it worked, but I can't tell which of
these are current, and whether some are left out, since there are 17739
comments at this moment, and new comments are made daily.


Code:
SELECT	 company.id AS companyid, comments.id, comments.supplier,
company.name
FROM		 comments RIGHT OUTER JOIN
					  company ON comments.supplier = company.name
How would I be able to tell which of these companies are current, and which
are old

The similarities are as follows:

comments.table companies.table old_companies.table
id id old_id
supplier name old_name
Reply With Quote
  #2 (permalink)  
Old 03-18-04, 08:20 AM
jake jake is offline
Newbie Coder
 
Join Date: Mar 2004
Location: UK
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Try doing a UNION on the two company tables, then joing the COmments table to that. e.g:-


SELECT Companies.CompanyId,
Companies.CompanyStatus,
Comments.Id,
Comments.Supplier
FROM Comments
LEFT JOIN
( SELECT id AS CompanyId, "Current" AS CompanyStatus, name as CompanyName FROM Company
UNION
SELECT old_id AS CompanyId, "Suspended" AS CompanyStatus, old_name AS CompanyName FROM Old_Company
) Companies
ON Comments.id = Companies.CompanyId




Quote:
Originally Posted by lordmerlin
Ok, I got three tables, company, comments and old_company.

In company are all the current companies, in old_company are companies who
have been suspended, and in comment, clients can make comments about the
companies, regardless if they are current or suspended companies.

I currently display all the comments on a page, but now I want to put an
icon next to the companies who are still with us, and another tick with the
suspended companies, making a clean indication as to which is which.

I tried the following statement, and it worked, but I can't tell which of
these are current, and whether some are left out, since there are 17739
comments at this moment, and new comments are made daily.


Code:
SELECT	 company.id AS companyid, comments.id, comments.supplier,
company.name
FROM		 comments RIGHT OUTER JOIN
					 company ON comments.supplier = company.name
How would I be able to tell which of these companies are current, and which
are old

The similarities are as follows:

comments.table companies.table old_companies.table
id id old_id
supplier name old_name
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
tables joins - 3 tables lordmerlin PHP 2 03-19-04 02:00 PM
Many tables or "sub" tables? rhunter007 PHP 5 12-02-03 12:37 PM
Linking two tables within a db Ported Valhalla PHP 2 10-14-03 10:36 AM
sorting multiple tables elmeto PHP 1 08-13-03 09:07 AM
script that measures height of tables and vertically aligns nested tables amj01 Script Requests 1 07-04-03 01:20 PM


All times are GMT -5. The time now is 04:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.