Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having two tables i.e a parent table & a child table such as

Category table with fields -> catid,category_name

& The other table is item -> itemid,catid,itemname,details,price.

What I need to do i bind a gridview on the items page where I need to display few details such as categoryname,itemname,details & price.

So what help I need is how to query, so that I get the category name from the category table through the catid stored in item table.

Tables is like

Category

Catid category_name
1 mouse
2 keyboard
3 mobile

Item

itemid catid itemname details price
1 1 logitech mouse 500
2 3 mobile mobile 5000

when in the gridview of the items page I want category name instead of that catid.

Please help.
Posted
Comments
Er Daljeet Singh 23-Apr-14 6:47am    
you need to use sql join for that
onlybigb321 23-Apr-14 6:53am    
That I know, but how.
Can you suggest me the query?

Try something like this for inner join if you want to show all the data from both the table.

SQL
SELECT table1.*,table2.* From table1 inner join table2 on table1.Column = table2.column where table1.column = '1'
 
Share this answer
 
Try:
SQL
SELECT it.itemId, it.catid, it.itemName, ct.Category_name, it.Price
FROM ItemTable it
JOIN CetegoryTable ct
ON it.Catid=ct.catid
 
Share this answer
 
Hello,

Following are the SQL query for getting complete result as you want:
SQL
SELECT C.Catid, C.category_name, I.itemid, I.itemname, I.details, I.price FROM Category C INNER JOIN Item I ON C.Catid == I.Catid


Thanks,
 
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