Professional Web Applications Themes

problem with many to many..... - MySQL

Having problem with many to many join or select understanding. Looking for help with the design or sql to get the member.member.lname with query 1 and cccb.com_name on query 2. Any help will be appreciated. TIA // sql selecting cccb(s) that member is on // 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'; // sql selecting member(s) on cccb // problem is can not get ...

  1. #1

    Default problem with many to many.....

    Having problem with many to many join or select understanding.

    Looking for help with the design or sql to get the member.member.lname
    with query 1 and cccb.com_name on query 2.

    Any help will be appreciated. TIA

    // sql selecting cccb(s) that member is on
    // 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';


    // sql selecting member(s) on cccb
    // 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 CHT=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 CHT=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 CHT=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';



    someone@somewhere.org Guest

  2. #2

    Default Re: problem with many to many.....

    Take a look at http://www.tonymarston.net/php-mysql/many-to-many.html

    --
    Tony Marston
    http://www.tonymarston.net
    http://www.radicore.org

    <org> wrote in message
    news:fqv7h.296732$ops.worldnet.att.net... 


    Tony Guest

  3. #3

    Default Re: problem with many to many.....

    Tony,

    Have visited that particular web page. Does not seem to answer my issue
    with reference to column data.

    org wrote:
     
    user Guest

Similar Threads

  1. contribute problem - access denied file may not existpermission problem
    By Al1973 in forum Macromedia Contribute Connection Administrtion
    Replies: 6
    Last Post: September 17th, 04:16 PM
  2. Replies: 0
    Last Post: August 23rd, 11:56 AM
  3. Replies: 0
    Last Post: August 2nd, 03:03 PM
  4. Replies: 2
    Last Post: July 17th, 07:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139