Jump to content

Archived

This topic is now archived and is closed to further replies.

romio

Linking my tables....

Recommended Posts

well am a bit confused, my database should include many categories and each category could have one or more product, i have designed both of my tables, but how will i proceed now, how do i join them....

[code]

CREATE TABLE categories
(
              
                 categoryID int(11) NOT NULL auto_increment RIMARY KEY,  
                 name varchar(255) default NULL,              
                 parent int(11) default NULL,                
                 products_count int(11) default NULL,        
                 description text,                            
                 picture varchar(30) default NULL,            
                 products_count_admin int(11) default NULL
);
[/code]
[code]
CREATE TABLE products
(                      
               productID int(11) NOT NULL auto_increment PRIMARY KEY,    
               categoryID int(11) default NULL,              
               name varchar(255) default NULL,              
               description text,                            
               customers_rating float NOT NULL default '0',  
               Price float default NULL,                    
               picture varchar(30) default NULL,            
               in_stock int(11) default NULL,                
               thumbnail varchar(30) default NULL,
               items_sold int(11) NOT NULL default '0',      
               big_picture varchar(30) default NULL,        
               enabled int(11) NOT NULL default '0',        
               brief_description text,                      
               list_price float default NULL,                
               product_code varchar(25) default NULL                    
);
[/code]

Share this post


Link to post
Share on other sites
Something like this

[code]SELECT c.name, p.productID, p.name, p.description, p.price
FROM products p
INNER JOIN categories c ON p.categoryID = c.categoryID
ORDER BY c.name, p.name[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.