If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Need help in fetching the record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-30-11, 05:34
rishibala143 rishibala143 is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
Need help in fetching the record

Hi

I had a table name tbl_purchase

CREATE TABLE IF NOT EXISTS `tbl_purchase` (
`pur_id` bigint(20) NOT NULL auto_increment,
`pur_code` varchar(100) NOT NULL,
`pur_tot_prod` varchar(100) NOT NULL,
`pur_prod_code` text NOT NULL,
`pur_dt` date NOT NULL,
`pur_status` char(1) NOT NULL,
PRIMARY KEY (`pur_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


Records in the table :

|---------------------------------------------------------------------------------------------|
| Pur_id | pur_code | pur_tot_prod | pur_prod_code | pur_dt | pur_status |
|---------------------------------------------------------------------------------------------|

1 PU1001 3 P2001|||P2002|||P2003 2011-02-03 Y
2 PU1002 2 P2001|||P2003 2011-02-04 Y
3 PU1002 1 P2004 2011-02-04 Y

This is how the values stored. Now i want to generate an report using product code.

If the user types P2003 it should fetch 2 records. Since the product code are stored like P2001|||P2002|||P2003.

How can i fetch ? Please help me....


Thanks & Regards
P.Balakrishnan
Reply With Quote
  #2 (permalink)  
Old 07-30-11, 06:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by rishibala143 View Post
Since the product code are stored like P2001|||P2002|||P2003.
there's your error right there -- this design fails first normal form

use a separate purchase_products table, with one row per product per purchase
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On