1
I’m having a problem at a select
in two tables that are returning the value twice.
I have the table businesses and table catalogues which are linked by company id. and catalogues.id_company. When I make a select
that has two or more catalogues of the same company, appears the company more than once.
CREATE TABLE IF NOT EXISTS `tbl_empresa` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `tbl_catalogos` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tbl_empresa_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `tbl_empresa_id` (`tbl_empresa_id`)
)
I need to select all companies that have catalogues.
How do I do this? What would the query look like?
Thank you very much! I was trying to do it for a long time. I was using a very complicated query and the solution was very simple. I used the GROUP BY, it worked perfectly. Thank you again!
– Lucas
I recommend you take some time later to study the most common structures of
SQL
! Read aboutjoin
,distinct
,group by
,order by
... Everyone ends up needing to make more complicated queries and spends more time trying to solve a specific problem than the time needed to study the basics ofSQL
:)– Daniel Dutra
I will. But my biggest difficulty at the time was a matter of logic because I was trying to pull everything only with Join and ect. The query had become huge and did not do what I needed. I think as a matter of practice. I will study and practice these questions more.
– Lucas