Brian E Boothe wrote:
how do i do 1 to many relationship?? i have this SQL syntax " i may need to add many issues per customer" so this is what i have
                          Please help
   SELECT *
FROM
 mcsdata.customers
 INNER JOIN mcsdata.issues ON (mcsdata.customers.id = mcsdata.issues.id)
WHERE
 (mcsdata.customers.id = mcsdata.issues.id)

Firstly - the 'ON' takes care of the join so you don't need it in the 'WHERE' as well.


Secondly for 1 -> many relationships you need at two tables:

create table customers (customerid int auto_increment primary key, customername varchar(255));

create table issues (issueid int auto_increment primary key, customerid int, issuetitle varchar(255));

Then you can do:

select * from customers c inner join issues i on (c.customerid=i.customerid);


If you want multiple customers to be associated with each issue you need 3 tables:

create table customers (customerid int auto_increment primary key, customername varchar(255));

create table issues (issueid int auto_increment primary key, issuetitle varchar(255));

create table customer_issues (issueid int, customerid int);

then you can do:

select * from
customers c, issues i, customer_issues ci
where
c.customerid=ci.customerid AND
ci.issueid=i.issueid;


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to