|
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
|
|
|
April 11th, 2005, 07:18 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
--------------------------------------------------------------------------------
|
April 11th, 2005, 08:24 AM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
April 11th, 2005, 08:29 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK thanks
Would I be able to do it if I have an column called email in each table?
|
April 11th, 2005, 10:56 AM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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..
|
April 12th, 2005, 03:02 AM
|
Registered User
|
|
Join Date: Mar 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
April 13th, 2005, 11:18 PM
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
April 14th, 2005, 03:23 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
April 14th, 2005, 09:15 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
The fields can have different names, but they must have the same data types and lengths. So you can use inner join.
|
April 20th, 2005, 11:56 PM
|
Authorized User
|
|
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
April 21st, 2005, 10:27 AM
|
Registered User
|
|
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how can i learn sql server 2000
and how can i start learning sql server 2000
plz help me ...
[email protected]
Mohammad Qasim
|
|
|