473,480 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cross join oddity?

I've hit a situation where I'm getting an unexpected set of results
from a cross
join that I've narrowed down to a table alias.

If I do (a has 4 rows, b has 1 row)
select a.field1, b.*
from a as maintable
cross join b

I get 16 rows returned. Is this expected behaviour or should an error
have been raised with the a. reference in the field list? postgres
7.2.3 on linux. (mssql and ingres both raise an error)

klint.
Nov 11 '05 #1
3 2145
Klint Gore wrote:
I've hit a situation where I'm getting an unexpected set of results
from a cross
join that I've narrowed down to a table alias.

If I do (a has 4 rows, b has 1 row)
select a.field1, b.*
from a as maintable
cross join b

I get 16 rows returned. Is this expected behaviour or should an error
have been raised with the a. reference in the field list? postgres
7.2.3 on linux. (mssql and ingres both raise an error)

klint.


It looks like each element in a is being matched up with each in
maintable. If you want to use the alias maintable, perhaps you should
write the query as
select maintable.field1, b.*
from a as maintable
cross join b
and put in your restrictions here (ie WHERE maintable.id = b.id)

Ron

Nov 11 '05 #2
rstp <rs**@linuxwaves.com> wrote in message news:<3F**************@linuxwaves.com>...
It looks like each element in a is being matched up with each in
maintable. If you want to use the alias maintable, perhaps you should
write the query as
select maintable.field1, b.*
from a as maintable
cross join b
and put in your restrictions here (ie WHERE maintable.id = b.id)


I did it that way when I got the incorrect result set.

In other DBMS that we use here (mssql,ingres,sybase), they all return
an error if you use the table name instead of the alias. I would have
expected postgres to do the same. So my question is more should it
raise an error rather than how to fix it?

klint.
Nov 11 '05 #3
Klint Gore wrote:
rstp <rs**@linuxwaves.com> wrote in message news:<3F**************@linuxwaves.com>...
It looks like each element in a is being matched up with each in
maintable. If you want to use the alias maintable, perhaps you should
write the query as
select maintable.field1, b.*
from a as maintable
cross join b
and put in your restrictions here (ie WHERE maintable.id = b.id)

I did it that way when I got the incorrect result set.

In other DBMS that we use here (mssql,ingres,sybase), they all return
an error if you use the table name instead of the alias. I would have
expected postgres to do the same. So my question is more should it
raise an error rather than how to fix it?

klint.

I don't think that it should raise an error as there are some instances
where you would want to access a table twice within one query, with an
alias and without. Eg to get information from tblUsers (fName, lName,
inputBy) where inputBy is another user in the table.

Ron

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7494
by: Tim Pascoe | last post by:
I am using the Dynamic Cross-Tab code supplied in an article from SQL Server Magazine (http://www.winnetmag.com/SQLServer/Article/ArticleID/15608/15608.html). I modified the script to generate a...
23
6477
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
5
1773
by: jmdocherty | last post by:
All, I've been trying to set up a CSS layout and all seems well in Firefox but in Safari it just seems to be plain weird! I hope someone can help tell me whether this is a problem with my code...
7
3039
by: Stephen Poley | last post by:
I have the following situation: - a table of employees, keyed on employee-id; - a table of training sessions, keyed on session-id; - a requirement to log who was present at which session, plus...
15
2595
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
69
8014
by: kabradley | last post by:
Alrighty Guys and Gals, I have another question that I hope you all can help me with. I have a report that uses a cross-tab query as its record source. This cross-tab query is getting all of its...
1
1021
by: karunajo | last post by:
hi, I want to calculate the quantity by partid against month using Cross tab query.. plz tel me how to write it.. I did select the pari id by using the following query select distinct...
2
2235
by: klaul | last post by:
Hoping someone can help me here! I'm having some problems trying to get the right syntax for a view, and am wondering if someone could point me in the right direction! My code is currently: ...
3
5030
atksamy
by: atksamy | last post by:
I have 2 tables like which i would like to query to form a new table. table 1 number type serial index 1000001 613 3 1 1000001 613 3 ...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.