Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for example :
i have two city like Mumbai, pune
and i have product like laptop,and mobile and also having different prize on base of city
when we select city like mumbai ,product like mobile prize is 200rs
and when we select city like pune ,product like mobile prize is 500rs
how it done?..
Posted

firstly please specify on which field you have primary key?
you can do like
SELECT prize FROM item_master WHERE product like 'mobile' and city like 'mumbai' from the same table.
 
Share this answer
 
SQL
Create table Product
(ProductID INT IDENTITY(1,1)
 ,ProductCode VARCHAR(50)
,ProductName VARCHAR(100)
);
Create table ProductPrice
(
ProductPriceID INT IDENTITY(1,1)
,ProductID INT 
,CityID INT
,Price NUMERIC(20,4)
)

Create table City
(
CityID INT IDENTITY(1,1)
,CityName VARCHAR(100)
)

add fk for city id and product id on Productprice table
 
Share this answer
 
You can setup your DB like below.

CREATE TABLE PRODUCT
(PRODUCTID INT IDENTITY(1,1)
 ,PRODUCTCODE VARCHAR(50)
,PRODUCTNAME VARCHAR(100)
);
CREATE TABLE PRODUCTPRICE
(
PRODUCTPRICEID INT IDENTITY(1,1)
,PRODUCTID INT 
,CITYID INT
,PRICE NUMERIC(20,4)
)
 
CREATE TABLE CITY
(
CITYID INT IDENTITY(1,1)
,CITYNAME VARCHAR(100)
)
 
 SELECT C.CITYNAME,P.PRODUCTNAME,PP.PRICE FROM PRODUCT P
 INNER JOIN PRODUCTPRICE PP ON P.PRODUCTID = PP.PRODUCTID
 INNER JOIN CITY C ON C.CITYID = PP.CITYID
 WHERE C.CITYID=1



ProductID,CityID are Foreign Keys in ProductPrice table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900