Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2005, 07:18 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Join

Hi,

Instead of having multiple queries (see below), can I combine them into one big query?

I need to see if a record for each user exists in each table.

Hope you can help

------------------------------------------------------
<cfquery datasource="#datasource#" name="getpd">
SELECT * FROM personaldetails WHERE pdemail = '#GetAuthUser()#';
</cfquery>
<cfquery datasource="#datasource#" name="geted">
SELECT * FROM education WHERE EDemail = '#GetAuthUser()#';
</cfquery>
<cfquery datasource="#datasource#" name="getjd">
SELECT * FROM employment WHERE Eemail = '#GetAuthUser()#';
</cfquery>
<cfquery datasource="#datasource#" name="gets">
SELECT * FROM skills WHERE semail = '#GetAuthUser()#';
</cfquery>
<cfquery datasource="#datasource#" name="ptdetails">
SELECT * FROM ptdetails WHERE ptemail = '#GetAuthUser()#';
</cfquery>

--------------------------------------------------------------------------------


 
Old April 11th, 2005, 08:24 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think so because you are having different tables with different column names..not sure about your database structure..may be you should try to normalize it in such a way you have to look for e-mail address in one column only.

 
Old April 11th, 2005, 08:29 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK thanks

Would I be able to do it if I have an column called email in each table?

 
Old April 11th, 2005, 10:56 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one of the way you can combine results in the query is using UNION operator..not sure you can use in your situation ..

SELECT emailfield FROM TABLE1
UNION
SELECT diffEmailfield From TABLE2

please provide us more details about your tables..
are these tables related in any way..then use INNER JOIN to join this tables..





 
Old April 12th, 2005, 03:02 AM
Registered User
 
Join Date: Mar 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you only need to see that record for each user exists in each table.you can create your own structure for UNION operation.

SELECT UserName='#GetAuthUser()#',TableName='personaldeta ils' FROM personaldetails WHERE pdemail = '#GetAuthUser()#'
UNION
SELECT UserName='#GetAuthUser()#',TableName='education' FROM education WHERE EDemail = '#GetAuthUser()#'

See if it help's



Cheers

Sunil
 
Old April 13th, 2005, 11:18 PM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

HI,

You need to use inner join.

Select A.* from A Inner Join B on A.EmailID=B.EmailID inner join C on B.EmailID=C.EmailID inner join D on ............

In this way. I am assuming that the email ID column in kept Unique in each table.

Hope u got my point.

B. Anant
 
Old April 14th, 2005, 03:23 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for all your help.

I am designing an online job application system, where users can create an online CV.

To make the data more managable, I decided to split up all the different info into seperate tables. The primary key for each table I will be using will be the users email address.

I name all the columns in each table with the initials of the table name first ie columns in the skills table with be prefixes with an 'S', colunms in the personal details table will be prefixed with 'PD'. So each column has a unique name.

So am I right in thinking I cannot use INNER JOIN with this structure?



 
Old April 14th, 2005, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The fields can have different names, but they must have the same data types and lengths. So you can use inner join.
 
Old April 20th, 2005, 11:56 PM
Authorized User
 
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hopes you are looking for this...

<cfquery datasource="#datasource#" name="getpd">
SELECT 'PersonalDetails' TableName, count(*) NumberOfRecords
FROM personaldetails WHERE pdemail = '#GetAuthUser()#'
UNION
SELECT 'education', count(*)
FROM education WHERE EDemail = '#GetAuthUser()#'
UNION
SELECT 'employment', count(*)
FROM employment WHERE Eemail = '#GetAuthUser()#'
UNION
SELECT 'skills', count(*)
FROM skills WHERE semail = '#GetAuthUser()#'
UNION
SELECT 'ptdetails', count(*)
FROM ptdetails WHERE ptemail = '#GetAuthUser()#'
</cfquery>

Cheers,
Pooja Falor
 
Old April 21st, 2005, 10:27 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qasimmangi Send a message via Yahoo to qasimmangi
Default

how can i learn sql server 2000
and how can i start learning sql server 2000
plz help me ...
[email protected]

Mohammad Qasim





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help using join in SQL query yogeshyl SQL Language 1 July 30th, 2008 04:12 AM
SQL INNER JOIN problem lawsoncobol Access VBA 1 August 17th, 2006 02:29 PM
My SQL, ASP, and Inner Join Knuckles2003 Classic ASP Databases 0 October 31st, 2005 02:24 AM
Please change the SQL to the one without JOIN kaz SQL Language 4 December 9th, 2003 05:51 PM
SQL Inner Join Problem tp194 Classic ASP Databases 2 July 8th, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.