Filter data with INNER JOIN - MYSQL

Asked

Viewed 550 times

0

Good afternoon, I’m new to the group I wanted to know where I’m going wrong...

I have a database search like this

**

SELECT * FROM Users INNER JOIN naturezanegocio ON Users.emaillogin = naturezanegocio.emaillogin
AND Users.paisorigem = '1'
AND Users.cidade = 'são paulo'
AND Users.estado = 'SP'
AND Users.numfuncionario > '0' < '10'
AND Users.registro = 'sim'
AND Users.investimento = 'sim'
AND Users.interesseparceria = 'sim'
AND Users.niveis_acesso_id = '0'
AND naturezanegocio.natureza IN ('2', '0', '0')
INNER JOIN tecnologia ON tecnologia.tecnologia IN ('5', '0', '0')

**

I need to return only the user who has all these requests, but he does not filter everything at once and instead table by table that ends up returning to me invalid users by not meeting all requirements...

where I went wrong?

  • This JOIN with TECHNOLOGY, you are not associating to anything of the query of Users and NATUREZANEGOCIO. One of the flaws is there.

  • I imagined it, but I couldn’t think of a solution to solve it, I would know how ?

3 answers

1

Apparently it’s a syntax error

Correct syntax:

SELECT column_name(s)
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;

SOURCE: www.w3schools.com/sql/sql_join_inner

  • in case I use 3 tables

  • Only use 2 INNER JOIN; eg: https://answall.com/questions/72710/inner-join-com-3-tables

0

Try it this way, I think it’ll help you

SELECT 
    *
FROM
    Users
        INNER JOIN
    naturezanegocio ON Users.emaillogin = naturezanegocio.emaillogin
        INNER JOIN
    tecnologia ON tecnologia.tecnologia = (Algum Identificador que Possua na tabela Users para fazer referencia)
WHERE
            Users.paisorigem = '1'
        AND Users.cidade = 'são paulo'
        AND Users.estado = 'SP'
        AND Users.numfuncionario > '0' < '10'
        AND Users.registro = 'sim'
        AND Users.investimento = 'sim'
        AND Users.interesseparceria = 'sim'
        AND Users.niveis_acesso_id = '0'
        AND naturezanegocio.natureza IN ('2' , '0', '0')
        and tecnologia.tecnologia IN ('5', '0', '0')
  • (Some Identifier You Have in the Users table to make reference) All tables have as reference emaillogin, tested Users.emaillogin and returned no results

  • managed to make work with the example you gave me above I will post the solution, the second INNER JOIN got like this "INNER JOIN technology ON technology.emaillogin = Users.emaillogin"

0

Solution

SELECT 
    *
FROM
    Users
        INNER JOIN
    naturezanegocio ON Users.emaillogin = naturezanegocio.emaillogin
        INNER JOIN
    tecnologia ON tecnologia.emaillogin = Users.emaillogin
WHERE
            Users.paisorigem = '1'
        AND Users.cidade = 'são paulo'
        AND Users.estado = 'SP'
        AND Users.numfuncionario > '0' < '10'
        AND Users.registro = 'sim'
        AND Users.investimento = 'sim'
        AND Users.interesseparceria = 'sim'
        AND Users.niveis_acesso_id = '0'
        AND naturezanegocio.natureza IN ('2' , '5', '0')
        and tecnologia.tecnologia IN ('5', '6', '0')
        group by Users.emaillogin

Browser other questions tagged

You are not signed in. Login or sign up in order to post.