473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

many to many problem

Having problem with many to many join. Below is the schema with tables
and sql statements. All seems to work with the following exception: Can
not get all the field names to display.
// problem is can not get 'member name' to display
// if put 'member.member_lname' in select statement get error msg
// Unknown column 'member.member_lname' in 'field list'

select member_cccp_lnk.member_dist_no, member_cccp_lnk.cccb_id,
cccb.com_name
from member_cccp_lnk
left join cccb on (cccb.cccb_id = member_cccp_lnk.cccb_id)
where member_cccp_lnk.member_dist_no = '0008';
// problem is can not get 'cccb name' to display
// if put 'cccb.com_name' in select statement get error msg
// Unknown column 'cccb.com_name' in 'field list'

select member.member_fname, member.member_lname
from member_cccp_lnk
left join member on (member.member_dist_no = member_cccp_lnk.member_dist_no)
where member_cccp_lnk.cccb_id = '0200';

create database cccb;

use cccb;

DROP TABLE IF EXISTS `cccb`.`cccb`;
CREATE TABLE `cccb`.`cccb` (
`cccb_id` int(4) unsigned zerofill NOT NULL,
`com_name` varchar(50) default NULL,
PRIMARY KEY (`cccb_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

insert into cccb (cccb_id, com_name) values
(150 ,'Annexation C'),
(200 ,'Advisory C'),
(800 ,'Protection C'),
(1000 ,'Transit C'),
(1050 ,'Water C');
DROP TABLE IF EXISTS `cccb`.`member`;
CREATE TABLE `cccb`.`member` (
`member_dist_no` int(4) unsigned zerofill NOT NULL,
`member_fname` varchar(14) NOT NULL,
`member_lname` varchar(14) NOT NULL,
PRIMARY KEY (`member_dist_no`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

insert into member (member_dist_no, member_fname, member_lname) values
(01, "Jerry", "Jones"),
(02, "Thomas", "Smith"),
(03, "Jack", "Nicholson"),
(04, "Anthony", "Ant"),
(05, "Gary", "Greece"),
(06, "Chad", "Chad"),
(07, "Celestine", "Pasta"),
(08, "Christopher", "Chris"),
(09, "Guss", "Guy"),
(10, "Steve", "Sterling"),
(11, "John", "Jones"),
(12, "Thomas", "Tomas");

DROP TABLE IF EXISTS `cccb`.`member_cccp_lnk`;
CREATE TABLE `cccb`.`member_cccp_lnk` (
`member_dist_no` int(4) unsigned zerofill NOT NULL,
`cccb_id` int(5) unsigned zerofill NOT NULL,
PRIMARY KEY (`member_dist_no`,`cccb_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

insert into member_cccp_lnk (member_dist_no, cccb_id) values
(01, 150),
(01, 200),
(01, 550),
(01, 600),
(01, 650),
(01, 850),
(02, 450),
(02, 650),
(02, 800),
(03, 400),
(03, 800),
(04, 350),
(04, 1050),
(05, 550),
(05, 950),
(06, 200),
(06, 550),
(06, 650),
(06, 800),
(06, 850),
(07, 100),
(07, 200),
(07, 250),
(07, 550),
(07, 650),
(08, 200),
(08, 800),
(08, 1000),
(09, 500),
(09, 550),
(10, 350),
(11, 200),
(11, 300),
(11, 350),
(12, 200),
(12, 350),
(12, 900);

select member_cccp_lnk.member_dist_no, member_cccp_lnk.cccb_id,
cccb.com_name
from member_cccp_lnk
left join cccb on (cccb.cccb_id = member_cccp_lnk.cccb_id)
where member_cccp_lnk.member_dist_no = '0008';

select member.member_fname, member.member_lname
from member_cccp_lnk
left join member on (member.member_dist_no = member_cccp_lnk.member_dist_no)
where member_cccp_lnk.cccb_id = '0200';

Nov 19 '06 #1
0 2515

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

Similar topics

8
by: Nils | last post by:
Hello, my problem: I merged about 1.000 Tables with Create table name (variables) type=merge union=(table1,table2,...,table1000); MySQL now creates a tables, but I can't open it....
2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
3
by: Adriaan van Heerden | last post by:
hi, once again apologies if I'm covering old ground. I've looked through lots of previous posts and tried some code but nothing works as yet. However, the problem must be a very common one so...
4
by: Apple | last post by:
I have to create a query with many to many relationship, but I can't break it into 2 x 1 to many, should there anyone can teach me how to solve this problem. Thanks in advance!
3
by: Shane Suebsahakarn | last post by:
I have a rather odd problem that I'm at a loss to explain. The mdb is in A2K2 format, and has many tables linked to around 3-4 different back end mdbs. It is running on a Win2K3 server (set up as...
2
by: ronenkf | last post by:
I am currently working on access 2003. Created database with 4 tables. For each on e there is a primary key, which is a text data type. Now I'm trying to configure relationship between tables. The...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: the other john | last post by:
The trouble currently with 3 tables. I'm excluding non-relevant fields... tbl_users PK_user_ID tbl_developers PK_developer_ID FK_developer_user_ID FK_developer_project_ID
11
by: RobertJohn | last post by:
Hi all I am using Access 2007 to start a small home library application, and so far it has two tables. 1. Books, with fields Book_ID (Primary Key) and Title, and 2. Authors, with fields...
9
by: manudega | last post by:
Hallo, I have a serious problem and I hope that you can help me. I have a database with 2 tables that have a many to many relationship: the Journalist table and the Article table. These two tables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.