Sample Header Ad - 728x90

MYSQL: Return a predefined value if result of join is null

0 votes
1 answer
259 views
Before all, sorry my very bad english level. Here's my problem. If i have two tables: 'Products' |id | product | |---|---------| |1 | "Fork" | |2 | "Spoon" | |3 | "Knife" | and 'taxes' |id | id_prod | tax | |---|---------|---------| |1 | 1 | 21 | |2 | 2 | 11,5 | If i execute the following command: SELECT product.*, taxes.tax FROM products LEFT JOIN taxes ON taxes.id_prod = products.id I will obtain this result. |id | product | tax | |---|---------|---------| |1 | "Fork" | 21 | |2 | "Spoon" | 11,5 | |3 | "Knife" | NULL | My question is: How i can give a default value when the product is not included in tax? I want to receive a result like this: If the default value is "21" |id | product | tax | |---|---------|---------| |1 | "Fork" | 21 | |2 | "Spoon" | 11,5 | |3 | "Knife" | 21 | How i can do that? Thanks in advance...
Asked by Matt Ross (23 rep)
Feb 10, 2023, 04:24 PM
Last activity: Feb 10, 2023, 04:30 PM