I really do not think you can do this by setting up as foreign keys. I would do the same as you had already mentioned... Implement by code. But I am interested and will take a peak up in the docs to see if this is possible. If I find anything that will make this possible, I shall report back. I'll look now. -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Marlon Brandão de Sousa Sent: Tuesday, September 18, 2007 3:31 PM To: programmingblind@xxxxxxxxxxxxx Subject: foreign keys deppending on two different tables in mysql Hello, I have this situation: Table a has an id and a name field Table b has an id and a name field Table c has an id field, an external code field and a name field The external code field of table c must be an existing id in table a or in table b, thus it is a foreign key. I do know, for example, how to make the external code field from table c deppend on the id field of table b ... what I don't know is if it is possible to make it refer to the id field from table b or to the id field of table a. I know this would cause some ambiguity in a ondelete rule, but what I need is to guarantee that the external field from table c will accept only values present on table a or on table b. Do you know if this is possible and, if it is, how to do it in the mysql database? Sure I can implement this in the code but I was woundering if it is possible to build this kind of rule in the database. Thanks Marlon -- When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind