Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •