PDA

View Full Version : Joining NON-Related Tables


user55
07-21-2007, 12:56 AM
Hi,

Is it possible to join non-related tables?


If I have one table called "community", how would I join it with the table "membership"? They don't have any related fields. I would like to display the data from the "membership" table in the "community" table:

community
==============
id
members
group

****************

membership
==============
memberspergroup
feepergroup

____________________________

Thanks,

Sara

Fumigator
07-21-2007, 01:04 AM
You don't have to specify a link between two joined tables, but your result will contain every row in your membership table times every row in your community table (that passes the WHERE conditions). For example-- if membership has 100 rows in it and community has 5 rows in it, and you do this:

SELECT community.id, community.members, community.group,
membership.memberspergroup, membership.feepergroup
FROM community
JOIN membership


Your results will contain 500 rows in it (100 membership rows times 5 community rows).

There is rarely a situation where this would be desirable.

user55
07-21-2007, 01:40 AM
Hi,

The data in the "membership" table will only be entered once and changed when necessary. So it applies to all of the "ID"s which is the primary key in the "community" table. Currently the "membership" table doesn't have a primary key. Hope this makes sense.

Sara

guelphdad
07-21-2007, 03:11 AM
perhaps you could show us some sample data from both tables and the expected output you would like to see.