Unix Technical Forum

Any experts with help?

This is a discussion on Any experts with help? within the MySQL forums, part of the Database Server Software category; --> Having problem with many to many join. Below is the schema with tables and sql statements. All seems to ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:37 AM
user
 
Posts: n/a
Default Any experts with help?

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';


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:37 AM
Jared
 
Posts: n/a
Default Re: Any experts with help?

Whats the problem,

I uploaded your db to mysql 5.0.27+GUI-TOOLS 1.2.5 BETA on WindowsXP and all
*4* queries ran sucessfuly with no errors, and return good data.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:38 AM
user
 
Posts: n/a
Default Re: Any experts with help?

// 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'

I have since created a join that works but I thought the joins I
submitted should have worked. I was looking for some thoughts as to why
they did not.



Jared wrote:

> Whats the problem,
>
> I uploaded your db to mysql 5.0.27+GUI-TOOLS 1.2.5 BETA on WindowsXP and all
> *4* queries ran sucessfuly with no errors, and return good data.
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:09 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com