CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Table Join to Get Multiple Records

Print topic Send  topic

Author Message
dodaniel

Posts: 43
Posted: 02/19/2009, 1:32 PM

I have 2 tables Forms and Users.
In my Forms table I have 3 fields Signature1, Signature2 and Signature3
The Signature fields are numeric fields that reference the User_ID field in the Users table.
The Users table has 3 fields User_ID, FirstName, LastName

I want to be able to dispay a name for each of the three signatures instead of the id number when I display the page.

How can I join the tables so that I can get the 3 different signature names to display from a single record in my Forms table?
View profile  Send private message
mentecky

Posts: 321
Posted: 02/19/2009, 2:32 PM

dodanial,

The SQL code would be something like:
  
SELECT  
   f.*,  
   CONCAT_WS(', ', s1.LastName, s1.FirstName) AS Sig1,  
   CONCAT_WS(', ', s2.LastName, s2.FirstName) AS Sig2,  
   CONCAT_WS(', ', s3.LastName, s3.FirstName) AS Sig3  
FROM  
   forms AS f,  
   users AS s1,  
   users AS s2,  
   users AS s3  
WHERE  
   f.Signature1 = s1.user_id AND  
   f.Signature2 = s2.user_id AND  
   f.Signature3 = s3.user_id;  
 

That would give you formatted names. In Query builder you can also drop 3 user tables and connect the Signatures to user_id in each user table.

Good Luck,

Rick
_________________
http://www.ccselite.com
View profile  Send private message
dodaniel

Posts: 43
Posted: 02/20/2009, 7:45 AM

I tried dropping the user table in 3 times and doing and Inner join and Left join and now I don't get any records from the table.
View profile  Send private message
dodaniel

Posts: 43
Posted: 02/20/2009, 2:30 PM

This worked....

Select *,
(Select user_id
From users
Where user_id = Signature1)
(Select user_id
From users
Where user_id = Signature2)
(Select user_id
From users
Where user_id = Signature3)
From dbo.Forms

View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.