Page 1 of 1
two tables
Posted: Fri Jan 26, 2007 2:38 am
by kpraman
Hello,
I have two tables, orders and order_details
order table contains the totalamt. orderdet contains amount for each products. I want to display both. i tried by using
Code: Select all
SELECT * FROM `orders`,order_details WHERE orders.orderId=order_details.order_id GROUP BY orderId
but i am not able to get it. should i have to use 2 queries?
Thanx
Posted: Fri Jan 26, 2007 2:42 am
by volka
example data and expected result would be nice.
If possible example data please as valid sql statements
Code: Select all
CREATE TABLE tablename (...);
INSERT INTO tablename ...;
makes it easier to test.
Posted: Fri Jan 26, 2007 2:51 am
by kpraman
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[syntax="sql"]CREATE TABLE `orders` (
`orderId` int(11) NOT NULL auto_increment,
`order_date` date NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`address` text NOT NULL,
`telephone` varchar(25) NOT NULL,
`fax` varchar(25) NOT NULL,
`email` varchar(255) NOT NULL,
`bill_amount` double(15,2) NOT NULL,
`status` varchar(255) NOT NULL,
`comments` text NOT NULL,
PRIMARY KEY (`orderId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
CREATE TABLE `order_details` (
`order_id` int(11) NOT NULL,
`productId` int(11) NOT NULL,
`prod_detId` int(11) NOT NULL,
`qty` int(11) NOT NULL,
`amount` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `order_details`
--
INSERT INTO `order_details` VALUES (1, 26, 1, 1, 34);
INSERT INTO `order_details` VALUES (1, 29, 5, 4, 100);
feyd | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Jan 26, 2007 2:58 am
by volka
- There's no record for `orders`.
- What's the expected result?