A
A
andreyabc2014-12-04 17:42:28
MySQL
andreyabc, 2014-12-04 17:42:28

JOIN from two tables?

there are 3 tables:

CREATE TABLE IF NOT EXISTS `workout` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trainer` int(11) NOT NULL COMMENT 'тренер',
  `client` int(11) NOT NULL COMMENT 'клиент',
  `gym` int(11) NOT NULL COMMENT 'зал',
  `year` int(11) NOT NULL COMMENT 'год',
  `month` int(11) NOT NULL COMMENT 'месяц',
  `day` int(11) NOT NULL COMMENT 'число',
  `sttime` varchar(5) NOT NULL COMMENT 'время начала',
  `entime` varchar(5) NOT NULL COMMENT 'время окончания',
  PRIMARY KEY (`id`),
  KEY `trainer` (`trainer`),
  KEY `client` (`client`),
  KEY `gym` (`gym`),
  KEY `year` (`year`),
  KEY `month` (`month`),
  KEY `day` (`day`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

CREATE TABLE IF NOT EXISTS `trainers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL COMMENT 'ФИО тренера',
  `phone` varchar(12) NOT NULL COMMENT 'номер телефона',
  `spec` text NOT NULL COMMENT 'специализация',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
faustxp, 2014-12-04
@faustxp

select
 *
from workout w
left join trainers t on w.trainer = t.id;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question