Make join in two tables in mysql

0

I have doubts about a query on mysql. I have two tables, one low call and the other called galleries. The low table has the id field and the name field and the galleries table has the id, the lower_id and the image. My question is this, would it be possible to make a query that would show me the name of the bass and if there is the id_low in the galleries table would show me the image and if not a script?

I tried to do a join but it only shows me the basses that have gallery which is not what I'm looking for.

Another option is to do it in two parts, first take out a list of basses and once with the list, check if you have an image or not and save the image or the script in an array.

Thank you very much

edit:

low table

CREATE TABLE IF NOT EXISTS 'bajos' (
  'id' int(11) NOT NULL AUTO_INCREMENT,
  'bajo' char(50) COLLATE utf8_spanish_ci DEFAULT NULL,
  KEY 'id' ('id'),
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;

galleries table

CREATE TABLE IF NOT EXISTS 'galerias' (
  'id' int(10) unsigned NOT NULL AUTO_INCREMENT,
  'id_bajo' int(11) DEFAULT NULL,
  'imagen_horizontal' varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY ('id')
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Join query

SELECT b.*, g.*
FROM bajos b, galerias g
WHERE b.id = g.id_bajo

Show only the bass that have a gallery, which I do not want.

If I make this query, more results come out of the account and it does not help me

SELECT b.*, g.*
FROM bajos b, galerias g
    
asked by Franxo Bass 29.01.2018 в 21:34
source

1 answer

0
select bajo, IFNULL(imagen_horizontal,'-') imagen
from bajos b
left join galerias g on b.id = g.id_bajo
    
answered by 29.01.2018 / 22:53
source