Does anyone know if mySQL supports nested SQL statements? I seems that it does not, but then again, it's sometimes a little difficult to find specific answers on mysql.com.
For example, say you have a system were users are entering some bit of data to a table, called datatable. There is a seperate table, used for authentication called userdata, that has the user specific information in it (username, names, user id, etc).
However, say you want to be able to know which user added any given record. To ensure integrity, you add something unique to the user to each new record automatically based on their userid, or username... whatever (as opposed to them entering their name when they create the record). I assumed user id (the id field in the usertable).
But, now, on the same report as you are listing the records from datatable, you want to to display the username instead of id. You could do it the long way (as you loop through the rows returned from datatable, run as seperate query on the usertable...), but what I'd like to know is if mySQL supports nested queries, so that I don't have to actually do any PHP coding to get any data from the datatable, if I already know something from it, but nothing from the usertable:
For example... the following query would, in a single statement, answer the question "What is the username of the person who entered the record for data code 170420990000?" without first looking up the data code and finding the enteredby value, then looking up that value in the usertable and finding the username... see what I mean?
SELECT * from usertable WHERE id=(SELECT enteredby FROM datatable WHERE datacode=170420990000)
Oracle has pretty advanced support for this... I'm just wondering if mySQL does this, or something like it.
thanks
.c