sanchez_1960
05-08-2008, 04:07 AM
I'm really stuck on this query. I have the following customer table:
CREATE TABLE `customers` (
`Customer_ID` int(10) NOT NULL auto_increment,
`Customer_Login` varchar(15) NOT NULL,
`Customer_Password` varchar(150) NOT NULL,
`Customer_Email` varchar(50) NOT NULL,
`Customer_Title` varchar(4) NOT NULL,
`Customer_Firstname` varchar(50) NOT NULL,
`Customer_Lastname` varchar(50) NOT NULL,
`Customer_Company` varchar(50) default NULL,
`Customer_Address1` varchar(50) NOT NULL,
`Customer_Address2` varchar(50) default NULL,
`Customer_City` varchar(50) NOT NULL,
`Customer_County` varchar(50) NOT NULL,
`Customer_Country` varchar(50) NOT NULL,
`Customer_Postcode` varchar(9) NOT NULL,
`Customer_Phone` varchar(20) default NULL,
PRIMARY KEY (`Customer_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
and the following two tables which customers review products and site reviews:
CREATE TABLE `reviews_customers` (
`ReviewC_ID` int(10) NOT NULL auto_increment,
`ReviewC_Date` date NOT NULL,
`ReviewC_Time` time NOT NULL,
`ReviewC_Status` varchar(1) NOT NULL,
`ReviewC_Text` text NOT NULL,
`ReviewC_Rating` int(1) NOT NULL,
`Review_ID` int(10) NOT NULL,
`Customer_ID` int(10) NOT NULL,
PRIMARY KEY (`ReviewC_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
CREATE TABLE `products_customers` (
`ProductC_ID` int(10) NOT NULL auto_increment,
`ProductC_Date` date NOT NULL,
`ProductC_Time` time NOT NULL,
`ProductC_Status` varchar(1) NOT NULL,
`ProductC_Text` text NOT NULL,
`ProductC_Rating` int(1) NOT NULL,
`Product_ID` int(10) NOT NULL,
`Customer_ID` int(10) NOT NULL,
PRIMARY KEY (`ProductC_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
I want to find the top customers from the second two tables and then print the results. I've done a similar thing before but combined in PHP, but I know this is not the way to do it. I want SQL to sort my results so I can just print the results.
CREATE TABLE `customers` (
`Customer_ID` int(10) NOT NULL auto_increment,
`Customer_Login` varchar(15) NOT NULL,
`Customer_Password` varchar(150) NOT NULL,
`Customer_Email` varchar(50) NOT NULL,
`Customer_Title` varchar(4) NOT NULL,
`Customer_Firstname` varchar(50) NOT NULL,
`Customer_Lastname` varchar(50) NOT NULL,
`Customer_Company` varchar(50) default NULL,
`Customer_Address1` varchar(50) NOT NULL,
`Customer_Address2` varchar(50) default NULL,
`Customer_City` varchar(50) NOT NULL,
`Customer_County` varchar(50) NOT NULL,
`Customer_Country` varchar(50) NOT NULL,
`Customer_Postcode` varchar(9) NOT NULL,
`Customer_Phone` varchar(20) default NULL,
PRIMARY KEY (`Customer_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
and the following two tables which customers review products and site reviews:
CREATE TABLE `reviews_customers` (
`ReviewC_ID` int(10) NOT NULL auto_increment,
`ReviewC_Date` date NOT NULL,
`ReviewC_Time` time NOT NULL,
`ReviewC_Status` varchar(1) NOT NULL,
`ReviewC_Text` text NOT NULL,
`ReviewC_Rating` int(1) NOT NULL,
`Review_ID` int(10) NOT NULL,
`Customer_ID` int(10) NOT NULL,
PRIMARY KEY (`ReviewC_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
CREATE TABLE `products_customers` (
`ProductC_ID` int(10) NOT NULL auto_increment,
`ProductC_Date` date NOT NULL,
`ProductC_Time` time NOT NULL,
`ProductC_Status` varchar(1) NOT NULL,
`ProductC_Text` text NOT NULL,
`ProductC_Rating` int(1) NOT NULL,
`Product_ID` int(10) NOT NULL,
`Customer_ID` int(10) NOT NULL,
PRIMARY KEY (`ProductC_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
I want to find the top customers from the second two tables and then print the results. I've done a similar thing before but combined in PHP, but I know this is not the way to do it. I want SQL to sort my results so I can just print the results.