Problem with inner join sql

0

I'm going crazy, I've tried several databases and it does not work to see if you can help me.

select 'Tienda.Codigo_de_barras' from "Tienda" inner join "Online" 
on 'Tienda.Codigo_de_barras' ='Online.Codigo_de_barras';

The code consists of seeing what products are available online and in the store. The code compiles but as a result it gives an empty table, and according to the data that I have entered, it must give several products. The two bar code variables are of type char (10), I tried to change the = by a LIKE but it gives the same result

    
asked by hugoboss 21.04.2018 в 19:48
source

2 answers

0

Your SQL query is poorly designed eliminates simple single and double quotes in the names of fields and tables:

select Tienda.Codigo_de_barras from Tienda inner join Online
on Tienda.Codigo_de_barras = Online.Codigo_de_barras;
    
answered by 21.04.2018 в 20:23
0

Hello!

I see that you are trying to relate two tables through joints, since they are not meant to be done on char or varchar data types (character strings). The boards are designed to be performed on numeric fields (int4, int8, numeric, etc).

Question : In your data definition (DDL) do you have a numeric field that links both tables?

If it is positive , I recommend that you execute the following query:

SELECT T.Codigo_De_Barras
FROM Tienda as T INNER JOIN Online as O ON (T.id = O.id)
WHERE T.Codigo_De_Barras LIKE '%LO QUE BUSCAS%'

You can vary between the use of "%" within the LIKE or even, simply use the "=" if you know the values specifically.

In case of being negative , I recommend that you rethink the design of your schema in the database. Remember that using a character string as the identifier of a table is never recommended. Why?. Because it consumes too many characters and will generate misuse of storage in all tables that refer to each other.

I hope that it has served you, otherwise it will expand more with your DDL sentences.

Greetings!

    
answered by 24.04.2018 в 17:19