Most voted "join" questions
Use this tag when the question refers to the syntax/behavior doubt of the JOIN command. A JOIN is a general operation in relational algebra for a combination operation on two or more relations in a relational database system; it is also the keyword of the SQL language to perform this operation.
Learn more…290 questions
Sort by count of
-
328
votes4
answers233186
viewsWhat is the difference between INNER JOIN and OUTER JOIN?
What’s the difference between INNER JOIN and OUTER JOIN? Can you give me some examples?
-
8
votes1
answer6038
viewsImplications of using Inner Join and left Join in a single select
I have some stored procedures in a SQL Server 2008 R2 database, these stored procedures have several joins, in some cases I used in it select, Inner Join and left Join, for example: Tabela Pessoa |…
-
8
votes3
answers948
viewsWhat makes a JOIN bad in a database?
Where I currently work I had to make some queries in the database to generate a report or take emails from students who did not do remakes in other courses. However, I was given the idea of making…
-
7
votes1
answer251
viewsProblem with logic when using LEFT JOIN
In my system, there is a system of posts and another of friendships. It follows the structure of tables: posts: id | usuario | conteudo | data | hora friendships: id | usuario1 | usuario2 | status…
-
7
votes1
answer99
viewsDoubt about using LEFT JOIN in mysql
I have the following problem: I have two tables. students and proof students have 10 students tests has 9 results (because one student missed) The union of the tables is given by the matricula…
-
7
votes2
answers12161
viewsDifference between RIGHT JOIN and LEFT JOIN
I have a little knowledge in relationship tables, read the answers to the question about What is the difference between INNER JOIN and OUTER JOIN?, and understood, theoretically. LEFT JOIN Returns…
-
6
votes1
answer609
viewsMysql JOIN with or without Foreign key?
What’s the difference between relating 2 tables using and not using a Foreign key? With regard to performance, it is recommended to use Foreign key to make the relationship? In which situation would…
-
6
votes2
answers361
viewsCount friends in common using LEFT JOIN
I have the following tables: users: id | usuario | pnome | snome | foto 1 | Igor | Igor | Souza | perfil.png 2 | Alex | Alex | Khal | foto.jpg 3 | Maria | Maria | Silva | foto.png friendships: id |…
-
6
votes1
answer144
viewsWhat is the Join() function for in the threading module?
I’ve seen the function join() for the module threading, but I didn’t quite understand what she does.
-
6
votes1
answer130
viewsDifference Between Using "FROM Table, Table2" X "Join Table ON Table2"
Considering the two forms of union of tables through a join(anyone): SELECT Tabela.A, Tabela.B, Tabela2.C FROM Tabela LEFT JOIN Tabela2 ON Tabela.Id = Tabela2.TabelaId And a union using from SELECT…
-
5
votes2
answers541
viewsProblem with LEFT JOIN using Pentaho Kettle
There is a behavior with respect to JOIN that I cannot understand. I have two tables in these formats Table Doente ID_Doente Doente 1 Pedro 2 Paulo 3 Rui Table query ID_Consulta ID_Doente Tipo 1 2…
-
5
votes1
answer326
viewsSELECT with sequential counter does not accept LEFT JOIN
Because by making a SELECT that returns a Sequence number doesn’t work if you have LEFT JOIN? SELECT @ROW_NUMBER:=@ROW_NUMBER+1 AS ROW_NUMBER, P.PEDIDOID FROM PEDIDO AS P, (SELECT @ROW_NUMBER:=0) AS…
-
5
votes2
answers1524
viewsCondition on Join or Where?
Is there any difference if I use: select * from a left join b on a.id = b.id and b.id2=1 where ... or select * from a left join b on a.id = b.id where b.id2=1 Sent on: Fri ? The first SQL returned…
-
5
votes2
answers1943
viewsUsing AND inside an INNER JOIN can?
I wonder if it is possible to use AND within a INNER JOIN, example: SELECT * FROM tab1 INNER JOIN tab2 ON tab2.id2 = tab1.id1 AND tab2.camp1 = 'valor' INNER JOIN tab3 ON tab3.id3 = tab2.id2; I gave…
-
5
votes1
answer142
viewsWhat is the difference between the new JOIN operator and the previous ones?
I was looking at some examples of SQL in Oracle, and I noticed that it is possible to do only JOIN. Example SELECT T1.*, T2.desc FROM table1 T1 JOIN table2 T2 ON T2.id = T1.id_table2 Question What…
-
5
votes3
answers245
viewsError doing Join with Laravel Query Builder
I’m doing the following Join: public function getStockDanger() { $data = DB::table('product') ->join('stock', 'product.id', '=', 'stock.product_id') ->where('stock.stock', '<=', 0)…
-
5
votes3
answers147
viewsJoin between banks
Staff I am running the command below but I haven’t gotten the desired result. USE banco1 SELECT * FROM sistema.tb_menus_perfil_params a LEFT JOIN banco2.sistema.tb_menus_perfil_params b ON a.pm_id =…
-
4
votes6
answers1555
viewsHow to do the following query without using INNER JOIN?
I have table A with the following fields: ID | ID_PAIS_ENVIO | ID_PAIS_RECIBO 1 | 23 | 47 //... I have table B with the following fields: ID | NOME_PAIS 23 | Brasil 47 | Portugal //... I need a…
-
4
votes2
answers96
viewsSearch performance involving multiple disks
Supposing that a query using JOIN between two or more tables, such as: SELECT * FROM foo INNER JOIN bar ON foo.id = bar.id There is performance gain if the table data is in different HD’s (due to…
-
4
votes1
answer1365
viewsCountdown in two tables
I’m having trouble counting items pertaining to neighborhoods. I need to list all the neighborhoods of the city X and show the items available cars and motorcycles. In the example I only used one…
-
4
votes2
answers179
viewsDoubt about using the Inner Join
I have 4 tables in my database Tabela Cadastro - idCadastro(PK) - IP Tabela Porta - idPorta(PK) - numero porta - idSwitch(FK) Tabela Porta_has_Cadastro - idCadastro(FK) - idPorta(PK) //Observação:…
-
4
votes2
answers1405
viewsSUM in SELECT with LEFT JOIN being multiplied
I have 3 tables in MYSQL. Bill: id nome 1 caio 2 zé 3 marcelo Followers (the account id, that is, the user has 2 followers): idqual 1 1 2 2 2 3 Products (the account id, that is, the user caio has 3…
-
4
votes2
answers25412
viewsUsing WHERE with INNER JOIN
There is a way to use one WHEREto make a SELECTwith INNER JOIN ? my case is this: SELECT CodCli, NomeCli FROM tbvendas INNER JOIN tbclientes ON tbvendas.CodCli = tbclientes.AutoCod I’d like to put a…
-
4
votes1
answer514
viewsSelect data from two tables to display in one column?
Consider the tables for customer registration : Table Person |ID|NOME|TIPO|EMAIL| Table Person Physical |ID|CPF| Person Juridical Table |ID| CNPJ| inscricao_municipal| inscricao_estadual| My goal is…
-
4
votes1
answer351
viewsMerge the contents of two lists by considering the contents in Python?
The scenario is this, I have two lists, ex: list1 = [1,2,3,4] list2 = [5,6,7,8] I want to generate a new list that looks like this: [15,26,37,48] That is, to "join" the elements of each index. I did…
-
4
votes1
answer75
viewsDoubt query in SQL Server - Information Association
My friends, good night! I need to perform a query in a database using SQL Server and I got stuck in a problem so I ask, please help from you. Here is an example summary of the problem: I have a…
-
3
votes3
answers563
viewsProblems with LEFT JOIN
I’ve been racking my brain for a few days with SQL on something that should be very simple, but I can’t fix it. I want to get all data from the table [Numorder] including those not in the table…
-
3
votes1
answer117
viewsAutomating Inner Join using Lookupcombobox component
Sometimes I use the Tdblookupcombobox component to bring a list of a dataset lookup field, this approach streamlines some things but is very limited. For example I have a list of stores in one…
-
3
votes2
answers608
viewsShow zero in group by SQL Server
I have a table that calls Ordem, on it has a field that represents the status of the service order (0 to 7), I need to plot a graph in Ireport, only I wanted to display in the legend the status name…
-
3
votes1
answer920
viewsHow to improve the performance of this SQL query?
Hello, first I will pass some pertinent data to the query. Tabela Contrato (id, id_cliente, status [ativo/inativo]) Tabela Cliente (id, nome) Tabela Dependente (id, id_cliente, nome, status…
-
3
votes2
answers2034
viewsPassing values from a select to subselect
I have the following query: SELECT rp.colaborador as codigo_, t.nome, count(rp.*) as presencas, ((100 * (select count(rp.*) from empresa.cad_reuniao_presencas rp join empresa.cad_terceiros t on…
-
3
votes1
answer159
viewsHow do I select multiple fields in the same query?
I created a dummy bank with the following structure: Below are also the numbered SQL Server scripts for database creation, if necessary. SQL Fiddle Now, what I want to do is make an appointment…
-
3
votes1
answer754
viewsWhat is the difference between the various JOIN types of SQL?
In SQL there are several types of JOIN, what is the difference between INNER JOIN, LEFT JOIN, CROSS JOIN, RIGHT JOIN and FULL JOIN?…
-
3
votes1
answer1898
viewsHow to return only records without matching in a JOIN?
I have a question regarding the use of JOIN in SQL in this case: I have a table produtos and a table destaques containing the id product. I need to make a query that returns only the records that…
-
3
votes2
answers999
viewsWhich is more efficient, perform multiple queries or use JOIN?
I have a table X that has my user data, and I need to return to the client the data related to that user in the table Y and Z. I can do it using JOIN or: SELECT attr1, attr2 FROM Y WHERE X_id = id…
-
3
votes1
answer253
viewsDoubt mysql and Left Join
I have the SQL below, which returns data that I will fill in some inputs of a form. The problem is that I have 20 items (pieces) in this table, but it may be empty because the user can fill any…
-
3
votes1
answer10458
viewsHow to use Inner Join in Laravel 5?
I have the following loop in a view table @foreach ($filme as $f) <tr> <td>{{ $f->fil_id }}</td> <td>{{ $f->fil_filme }}</td> <td>{{ $f->fil_sinopse…
-
3
votes3
answers161
viewsHow to perform a select by multiple fk?
I have a question about one (or more) select. I have the following bank created and I need to do a search for a certain recipe based on one (or more, and here’s the problem) ingredients. How can I…
-
3
votes1
answer6005
viewsUsing Case When with Leftjoin
I am mounting a proc, but depending on the value of a parameter, I would like left Join to be different. I tried the kerys below: That works, but the else as null or even without the else, if the…
-
3
votes1
answer59
viewsDifferent ways to do a query that performs an SQL merge
I learned to do SQL queries with joins as follows: SELECT u.NOME, e.RUA FROM usuarios u, endereco e WHERE e.ID_USUARIO = u.ID ORDER BY u.NOME As you can see, the query searches the name of users and…
-
3
votes2
answers142
viewshow to query data in a table that is not related to the other table?
I have the following tables: CREATE TABLE IF NOT EXISTS `categoria` ( `id` INT NOT NULL AUTO_INCREMENT, `nome` VARCHAR(25) NOT NULL, `descricao` VARCHAR(100) NULL, PRIMARY KEY (`id`)) ENGINE =…
-
3
votes4
answers5888
viewsSelect with multiple Left Joins Sql Server
I took an example of people registering with the following structure: I’m trying to make a SELECT in tblPessoa with JOIN with the intention that select returns data from the table in which Id…
-
3
votes1
answer188
viewsDoubt Inner Join, left Join mysql
I am working with the following tables: CREATE TABLE livro ( Id_livro int NOT NULL, Nome_livro CHAR(40) NOT NULL, Pg int, Edicao int, Editora int NOT NULL, Assunto int NOT NULL, Preco decimal (5,2)…
-
3
votes3
answers68
viewsHow is Join and WHERE made with multiple tables?
I have 4 tables they are already with Foreign key. aluno: id matricula username curso_id // referencia a id_cursos da tabela cursos, coluna id_cursos. cursos: id_cursos nome_cursos modulos:…
-
3
votes1
answer1298
viewsFULL OUTER JOIN generates errors
I am trying to run the following Mysql script SELECT `AccessDayClass`.`total` AS 'em aula', `AccessDayNotClass`.`total` AS 'em casa', `AccessDayClass`.`DateOnly` AS 'week' FROM `AccessDayNotClass`…
-
3
votes1
answer46
viewsJunction of tables
I got three tables a call CRM_PROCESSO, another call CRM_PROCESSO_VARIAVEL and the last call CRM_PROCESSO_ATIVIDADE, both have the variable idprocesso in common. What I need is for command to bring…
-
3
votes3
answers97
viewsRelationship between the tables
I have the following tables: TB_ESTOQUE |COD_PRODUTO|QT_DISPONIVEL|COD_FILIAL| | 0856322 | 5 | 41 | | 0856351 | 2 | 41 | | 0856322 | 9 | 114 | | 0856720 | 3 | 20 | | 0856322 | 8 | 128 | | 0856322 |…
-
3
votes1
answer217
viewsHow to use denial in Contains c# with LINQ?
I need help, I’m starting in development, eclistIds returns me two ids, and if I don’t use the negation ( ! ) it returns me the id I don’t want, when I use the negation to return the other id,…
-
3
votes2
answers72
viewsHow to turn a column with a sentence per row into a column where each row is a word of these phrases?
I have the following structure: structure(list(frases = c("agricultura pecuária e serviços relacionados", "produção de lavouras temporárias", "cultivo de cereais", "cultivo de arroz", "cultivo de…
-
2
votes2
answers707
viewsQuery Mysql returns no error or result
I have five tables in which each one of them has data that I need to be displayed grouped by date. Proposals are grouped by date, number of proposals, value of proposals, media, amount invested,…