MySQL Forums
Forum List  »  PHP

Problem to select data via JOIN with many tables
Posted by: Pieter Vdb
Date: September 23, 2011 09:25AM

Hi,

Following database structure:

CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`personsId` int(11) NOT NULL,
`typeId` int(11) NOT NULL,
`username` varchar(100) NOT NULL,
`password` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=225 ;

CREATE TABLE `schools` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`namem` varchar(100) NOT NULL,
`director` varchar(150) NOT NULL,
`mailadres` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

CREATE TABLE `users_schools` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`usersId` int(11) NOT NULL,
`schoolsId` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=225 ;

CREATE TABLE `lessons` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`schoolsId` smallint(6) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=239 ;

CREATE TABLE `persons` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`address` varchar(100) NOT NULL,
`email` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=283 ;

CREATE TABLE `points` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lessonsId` int(11) NOT NULL,
`usersId` int(11) NOT NULL,
`score` double NOT NULL,
`remark` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;

CREATE TABLE `type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`level` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

I want a view to make a list with name (table persons), score and remark (table points) for all persons who have a record in table Users.
I want to specify also a specific school and lesson.

Can someone help me? Via Google I found many examples for JOIN query's, but no one with so many tables.

Pieter

Options: ReplyQuote


Subject
Written By
Posted
Problem to select data via JOIN with many tables
September 23, 2011 09:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.