two tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

two tables

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

  • There's no record for `orders`.
  • What's the expected result?
Post Reply