| Author |
Topic |
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 01:45:02
|
| Hi all. how could i join unrelated tables?for example:table1: employeedcno name address telno1 sarah philippines 1112 john india 2223 joy usa 333table2: hospitalhospname location ownerhosp1 loc1 billgateshosp2 loc2 annhosp3 loc3 lovehosp4 loc4 victable3: studentstudname loadkim 10Is it possible to join unrelated tables? Thanks-Ron- |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 01:46:58
|
Yes. But you have to tell us what is your expected result KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 01:47:46
|
| You most probably will create cartesian products, or CROSS JOINs.Peter LarssonHelsingborg, Sweden |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 01:55:47
|
| OK. considering table1 and table3 only.expected result:name address telno studname loadsarah philippines 111 kim 10john india 222 kim 10joy usa 333 kim 10 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 01:58:37
|
Yup. As Peter said. A cross joinselect name, address, telno, studname, loadfrom employee cross join student KH |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 02:00:34
|
| Ohhh a simple as that?thanks KH and Peter.-Ron- |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 02:04:26
|
| I have a difficulty in cross joining.how could i cross join this 2 separated queries?select a.*, (a.HospStreetBldg1 + ', ' + a.HospStreetBldg2 + ', '+ a.HospTownCity + ', ' + a.HospProvince) as Address, getdate() as datenow from appsysconfiggeneralselect D.fullname, P.religion, E.empno from pspersonaldata as Pinner join hremployees as E on P.dcno = E.empdcno inner join psdatacenter as D on D.dcno = E.empdcnowhere P.religion =@RELIGIONthanks-Ron- |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 02:10:57
|
[code]select *from(select a.*, (a.HospStreetBldg1 + ', ' + a.HospStreetBldg2 + ', '+ a.HospTownCity + ', ' + a.HospProvince) as Address, getdate() as datenow from appsysconfiggeneral a) across join(select D.fullname, P.religion, E.empno from pspersonaldata as Pinner join hremployees as E on P.dcno = E.empdcnoinner join psdatacenter as D on D.dcno = E.empdcnowhere P.religion =@RELIGION) b[/code] KH |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 02:16:59
|
| It has errors.these are the errors:Msg 107, Level 15, State 1, Line 1The column prefix 'a' does not match with a table name or alias name used in the query.Msg 4104, Level 16, State 1, Line 1The multi-part identifier "a.HospStreetBldg1" could not be bound.Msg 4104, Level 16, State 1, Line 1The multi-part identifier "a.HospStreetBldg2" could not be bound.Msg 4104, Level 16, State 1, Line 1The multi-part identifier "a.HospTownCity" could not be bound.Msg 4104, Level 16, State 1, Line 1The multi-part identifier "a.HospProvince" could not be bound.Msg 8155, Level 16, State 2, Line 1No column was specified for column 1 of 'a'.thanks.-Ron- |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 02:21:35
|
i have edited my post. Your original query did not defined the alias 'a' KH |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-03-06 : 02:22:29
|
| Oh great! thanks KH.-Ron- |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 02:27:35
|
| Make use of derived tables.SELECT *FROM (query1) AS xCROSS JOIN (query2) AS yPeter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 02:28:17
|
Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 02:37:05
|
quote: Originally posted by Peso
Peter LarssonHelsingborg, Sweden
Got distracted ? Browser refresh button not working ?  KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 02:38:40
|
Had to do some actual work Peter LarssonHelsingborg, Sweden |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-06 : 02:43:31
|
Mere 16.6333 minutes difference Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-06 : 02:44:01
|
quote: Originally posted by Peso Had to do some actual work Peter LarssonHelsingborg, Sweden
You are not joking right ? Actual Work ?  KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-06 : 02:45:02
|
| Yes. That was my effort for today.Now I can play along here all day!Peter LarssonHelsingborg, Sweden |
 |
|
|
|