i have three tables with structure
CREATE TABLE IF NOT EXISTS `refrence` (
`products_ref_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`categories_id` int(11) NOT NULL,
`Product_property` varchar(255) NOT NULL,
`Product_reference` varchar(50) NOT NULL,
PRIMARY KEY (`products_ref_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
CREATE TABLE IF NOT EXISTS `product_details` (
`products_id` int(11) NOT NULL AUTO_INCREMENT,
`categories_id` int(11) NOT NULL,
`FieldA` varchar(30) NOT NULL,
`FieldB` varchar(50) NOT NULL,
`FieldC` varchar(255) NOT NULL,
`FieldD` varchar(255) NOT NULL,
`FieldE` varchar(255) NOT NULL,
`FieldF` varchar(255) NOT NULL,
`Field_desc` text NOT NULL,
PRIMARY KEY (`products_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=98 ;
Here i am extracting Product_reference value from refrence table with respect to Product_property & categories_id as
SELECT Product_reference FROM refrence where categories_id=3 AND Product_property ='xxx'
Now this Product_reference is the field name in product_details table suppose result is abc. So i want to extract distinct abc from product_details table as
SELECT Distinct abc FROM product_details where categories_id=3
Now i want to combine both the query to one, What is the way to write these queries in to single one.
I tried this
SELECT Distinct (
SELECT Product_reference FROM refrence where categories_id=3 AND Product_property ='xxx'
) as aa FROM product_details where categories_id=3
But its not working, may be i am missing some syntax.
refrencefor recordswhere categories_id=3yetproduct_detailsfor recordswhere categories_id=1- and your explanation of what your query is intended to do is very hard to understand. Perhaps you can clarify?