On Fri, 2011-05-06 at 09:00 +0100, Rocio Gomez Escribano wrote: > Tables "client" an "user" are quite similar, but they don't have any > intersection, I mean, if somebody is a client, he or she cant be a user. So, > I have his or her driving license and I need to know what kind of person is. > > Im trying some join left, right, but I'm unable to get it!! >
OK, a couple of questions: Are you absolutely sure the two sets of people are mutually exclusive? Why use two separate "user" and "client" tables rather than one "person" table with a typeId which foreign keys on to a personType table? Is the output of two columns named PersonType,PersonId acceptable for this query? Assuming your design is correct as it stands or fixed in its current state you can achieve what you want with a join. select null as userID, clientID from client where clientCodeDrivingLicense = 321321321 UNION select userId, null as clientID from user where userCodeDrivingLicense = 321321321 With regard to the performance of this system over time I'd suggest you want a unique index on the DrivingLicense column/columns. Hope that helps, Nigel -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org