mysql - How to merge SQL SELECT fields -
I had a MySQL table with an ENUM. Since I had to change this ENUM occasionally, so I moved it to another table. Now I have to make a statement, which will give me the name of enum / newTable in a selection area.
Table 1 (Bottle):
id | Size | Size_id1 Small | (NULL 2) Medium | (NULL) 3 | Big | (NULL) 4 | (NULL) | 1 5 | (NULL) | 2 6 | (NULL) | 3 Table 2 (bottle_size):
id | Name 1 Small 2 Medium 3 Select larger :
SELECT id, & lt; Dontknow & gt; As the size of the size of the bottle, the left hold bottle size is b.size_id = bz.id where size = 'small';
> If you do not have the NULL or the second field, then you can use the first field to select. Because it returns results in a dynamic area ("size"), you must use WHERE instead of HAVING to add a condition: SELECT b.id, IFNULL (b.size, bz.name) Size as bottle B shape size Bottle size bz.sid_id = bz.id HAVING size = 'small'; Demo:
Comments
Post a Comment