DJ <[EMAIL PROTECTED]> wrote on 09/23/2005 12:22:58 PM: > i want to insert a row into table1 only if the value being inserted on > table1 exists on table2 primary id. > > can i do this with subquery? > > thanx. > > > -- > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.344 / Virus Database: 267.11.5/110 - Release Date: 9/22/2005 >
Depending on what version MySQL you are using, probably not. A very robust method of doing what you propose is to allow MySQL to do it for you by establishing a Foreign Key from table1 to table2. One drawback is that both tables need to be InnoDB (which you may not want to support). What version are you using and what is the possibility of using InnoDB with your appliation? Shawn Green Database Administrator Unimin Corporation - Spruce Pine PS: always CC the list on all responses (unless you intentionally mean to take the conversation off-list)