There is a stuff_id table with id and name fields.
There is a table stuff_phone with fields id , phone , preference .
One employee may have multiple phones. One of his phones may have a preference, in which case for this phone there is some kind of label in the preference field, say 'p' .
We need a request that displays information in the form of "name - number" for all employees, and for each employee you need to display only one number, and if he has a number with a preference, then this one, otherwise any.
How to write such a request?
UPD: For linking tables, the id field is used. You can consider the preference field bitwise - not the point. I would like some kind of standard ANSI solution that would work everywhere, and no matter what implementation. The main thing is the essence of the issue, not nuances. How to make a table join so that a name is assigned to one number from a set?
stuff_idto the number table to connect the number with the person, otherwise how will you understand which number belongs to what? Thepreferencefield is a flag, so make it according to the DB dialect in the bit or integer field, so that the values are 0 or 1. And then read about the subqueries. - teranmysql,sql server,oracle,ms access, etc. in question tags - teran