Как написать запрос по всем данным
-- phpMyAdmin SQL Dump
-- version 4.9.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: May 20, 2020 at 07:33 AM
-- Server version: 5.7.24
-- PHP Version: 7.4.1 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */;
--
-- Database: `d_base`
--
-- --------------------------------------------------------
--
-- Table structure for table `devices`
-- CREATE TABLE `devices` ( `id` int(11) NOT NULL, `Name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `devices_atribut`
-- CREATE TABLE `devices_atribut` ( `id` int(11) NOT NULL, `devices_id` int(11) DEFAULT NULL, `Name` varchar(255) NOT NULL, `Code` varchar(255) NOT NULL, `Username` varchar(11) NOT NULL, `Section` varchar(255) NOT NULL, `ip_adrerss` varchar(255) NOT NULL, `OS` varchar(255) NOT NULL, `Login` varchar(255) NOT NULL, `Host_Name` varchar(255) NOT NULL, `CPU` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `devices_atribut`
-- INSERT INTO `devices_atribut` (`id`, `devices_id`, `Name`, `Code`, `Username`, `Section`, `ip_adrerss`, `OS`, `Login`, `Host_Name`, `CPU`) VALUES (9, NULL, 'dfgdfg', 'dfgdfgdf', 'dfgd', 'gdfg', '65656565', 'dfgdfg', 'dfgdfg', 'dgdfg', 'dfgdfgd');
-- --------------------------------------------------------
--
-- Table structure for table `devices_type`
-- CREATE TABLE `devices_type` ( `id` int(11) NOT NULL, `Name` varchar(255) NOT NULL, `devices_st_id` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `devices_type`
-- INSERT INTO `devices_type` (`id`, `Name`, `devices_st_id`) VALUES (37, 'dfgdgd', NULL), (38, 'fdf', 47), (39, 'fdf', 47);
-- --------------------------------------------------------
--
-- Table structure for table `statuses`
-- CREATE TABLE `statuses` ( `id` int(11) NOT NULL, `device_id` int(11) DEFAULT NULL, `status_name` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `statuses`
-- INSERT INTO `statuses` (`id`, `device_id`, `status_name`) VALUES (39, NULL, 'use');
-- --------------------------------------------------------
--
-- Table structure for table `statuses_chekid`
-- CREATE TABLE `statuses_chekid` ( `id` int(11) NOT NULL, `time` datetime(6) NOT NULL, `status_id` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `statuses_chekid`
-- INSERT INTO `statuses_chekid` (`id`, `time`, `status_id`) VALUES (24, '2020-05-14 00:00:00.000000', NULL);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `devices`
-- ALTER TABLE `devices` ADD PRIMARY KEY (`id`);
--
-- Indexes for table `devices_atribut`
-- ALTER TABLE `devices_atribut` ADD PRIMARY KEY (`id`), ADD KEY `devices_id` (`devices_id`), ADD KEY `devices_id_2` (`devices_id`);
--
-- Indexes for table `devices_type`
-- ALTER TABLE `devices_type` ADD PRIMARY KEY (`id`), ADD KEY `devices_st_id` (`devices_st_id`);
--
-- Indexes for table `statuses`
-- ALTER TABLE `statuses` ADD PRIMARY KEY (`id`), ADD KEY `device_id` (`device_id`);
--
-- Indexes for table `statuses_chekid`
-- ALTER TABLE `statuses_chekid` ADD PRIMARY KEY (`id`), ADD KEY `status_id` (`status_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `devices`
-- ALTER TABLE `devices` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=48;
--
-- AUTO_INCREMENT for table `devices_atribut`
-- ALTER TABLE `devices_atribut` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
--
-- AUTO_INCREMENT for table `devices_type`
-- ALTER TABLE `devices_type` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;
--
-- AUTO_INCREMENT for table `statuses`
-- ALTER TABLE `statuses` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;
--
-- AUTO_INCREMENT for table `statuses_chekid`
-- ALTER TABLE `statuses_chekid` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `devices_atribut`
-- ALTER TABLE `devices_atribut` ADD CONSTRAINT `s2` FOREIGN KEY (`devices_id`) REFERENCES `devices` (`id`);
--
-- Constraints for table `devices_type`
-- ALTER TABLE `devices_type` ADD CONSTRAINT `s1` FOREIGN KEY (`devices_st_id`) REFERENCES `devices` (`id`);
--
-- Constraints for table `statuses`
-- ALTER TABLE `statuses` ADD CONSTRAINT `s3` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`);
--
-- Constraints for table `statuses_chekid`
-- ALTER TABLE `statuses_chekid` ADD CONSTRAINT `s4` FOREIGN KEY (`status_id`) REFERENCES `statuses` (`id`); COMMIT;
Запрос:
SELECT * FROM `devices`
LEFT JOIN `devices_atribut`
ON `devices`.id = `devices_atribut`.`devices_id`
LEFT JOIN `statuses`
ON `devices`.id = `statuses`.`devices_id`
LEFT JOIN `statuses_chekid`
ON `statuses`.id = `statuses_chekid`.`status_id`
LEFT JOIN `devices_type` ON `devices`.id = `devices_type`.devices_st_id