Hi Chris, What you are trying to do is an outer join, meaning that you want to join the two tables on field1, but you want to get all of the records from table 1 even if no row from table2 matches.
You can check the MySQL doc for this, as the MySQL syntax is not too familiar to me, but I think it would go something like this: SELECT table1.field1, table1.field2, table2.* FROM table1 LEFT JOIN party ON table1.field1 = table2.field1 ORDER BY table1.field1, table1.field2 "table1 LEFT JOIN table2" tells MySQL to include all of table1 (the one on the left) HTH Jean-Claude > -----Original Message----- > From: Chris Rogers [mailto:[EMAIL PROTECTED]] > Sent: December 24, 2002 9:08 AM > To: [EMAIL PROTECTED] > Subject: Help with connecting two tables. > > > I am using mysql version 3.23.41 and perl version 5.6.1-26.72.3 with > perl-DBI version 1.18-1. I'm having trouble putting together a statement > that will get specific fields from all the records in table1 and all the > fields from table2 where certain fields match the first table. My problem > is that if there is no record in table2 with fields that match > the specified > fields in table1, the record for table1 is not returned. I hope > this is not > confusing for you gurus but it is for me. Here is a statement > that I tried: > > SELECT table1.field1, table1.field2, table2.* FROM table1, table2 WHERE > table1.field1 = table2.field1 ORDER BY table1.field1, table1.field2 > > I also tried this but it produced an SQL syntax error: > > (SELECT table1.field1,table1.field2 FROM table1) UNION (SELECT * FROM > table2) ORDER BY table1.field1,table1.field2 > > I expected a return of records at least equal to the number of records in > table1. The first two fields is the returned set should all have > values but > I expected many of the remaining fields to be blank for many of > the records. > > > Any help would be greatly appreciated and if I've been unclear, please let > me know and I will try to explain it better but this is really > confusing me. > > Thanks, > Chris
