MySQL Forums
Forum List  »  PHP

Query to group results according to parent attribute
Posted by: Bill Bernoulli
Date: July 24, 2013 04:11AM

Hello and thank you in advance.

I have a table like that:

CREATE TABLE IF NOT EXISTS `Test` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`Parent` VARCHAR(45) NOT NULL ,
`Child` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;


INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('1', 'X', 'a');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('2', 'X', 'b');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('3', 'X', 'c');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('4', 'Y', 'a');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('5', 'Y', 'b');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('6', 'Z', 'a');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('7', 'W', 'a');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('8', 'W', 'b');
INSERT INTO `Test` (`ID`,`Parent`,`Child`) VALUES ('9', 'W', 'c');


I would like if exists a way to print (on a html page) something like that:

X
a
b
c

Y
a
b

Z
a

W
a
b
c


Thank you

Options: ReplyQuote


Subject
Written By
Posted
Query to group results according to parent attribute
July 24, 2013 04:11AM


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.