Using INNER JOINs with USING, ON or WHERE (where tabla.column)

0

I've learned the USING doing things like this:

SELECT nufactura,des,cantidadc,precio,precio*cantidadc AS "SUBTOTAL"
FROM 'facturas' INNER JOIN 'fac_pro' USING(nufactura)INNER JOIN 'productos' USING(codigop)
WHERE nufactura = "700" 
ORDER BY cantidadc DESC

but I have not really understood your order very well or why it is so, much less the use with ON and WHERE and that call with nombre.nombre1. That point I do not know what he really does. Is it the same as FROM ? Is it like a pointer or something?

    
asked by HeckDan 24.05.2017 в 03:15
source

1 answer

2

When you concatenate 2 tables you need to indicate which fields are the ones that relate the tables.

Normally ON is used by default:

SELECT * FROM T1 INNER JOIN T2 ON T1.id_t2 = T2.id

In some cases the names of the tables are the same, for this a shortcut is to use USING Let's suppose that T1 has a field that is called id_foo same as T2 that also has a field called id_foo that relates them.

You can use ON normally:

SELECT * FROM T1 INNER JOIN T2 ON T1.id_foo = T2.id_foo

Or simply use the USING:

SELECT * FROM T1 INNER JOIN T2 USING(id_foo)
    
answered by 24.05.2017 в 12:03