I have this tableproductos
-----------------------------
| product | Nombre |
-----------------------------
| 58 | RANCH |
-----------------------------
| 60 | GUACAMOLE |
-----------------------------
| 52 | CEBOLLA |
-----------------------------
and this tableproductoBodega
----------------------------------------------------
| product | NombreB | CantidadB |
----------------------------------------------------
| 58 | RANCH | 10 |
----------------------------------------------------
| 61 | GUACAMOLE | 8 |
----------------------------------------------------
| 53 | TOMATE | 1 |
----------------------------------------------------
What I'm trying to do is get a result like the following.
-----------------------------
| product | NombreB |
-----------------------------
| 58 | RANCH |
-----------------------------
| 61 | GUACAMOLE |
-----------------------------
| 52 | CEBOLLA |
-----------------------------
| 53 | TOMATE |
-----------------------------
But without doing it with a Union
since then I have to do another query like showing the cantidad
and if it doesn't have a quantity put 0
, I just don't know how to join it without using theUnion
i had this
SELECT
Nombre
NombreB
FROM productos
INNER JOIN productoBodega ON product = product
but I don't know how to join Nombre
withNombreB
what you need is to do a full outer join
Cheers
If you want the result to look like a single table, then it's best to do a
UNION
. I'm not sure why that solution doesn't work for you.What I would do is this:
You can use
UNION
even if you later have to make another query for the amount or what you need:You can now use this block in other queries as a single table named TABLE_PROD with 2 fields PRODUCT and NAME .
For example if you need to get the quantity now you can use the block with one
JOIN
as you normally would (instead of TABLE_PROD I used TU for short:Here you can see how the whole block
UNION
is treated as a table called TU with 2 fields.