473,419 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Adjacency model problem

4
Hi all,

The table structures are below.

The table category_cat is built on the adjacency model (where the parent and child entries are both stored in the same table). For my problem, I've created 3 tables for example. The category_cat table containts drill-downs of pets (from animal type to animal color). I have the table product_pdt that containts "I hate shirts" of every animal category. And the table pdttocat_ptc joins the other 2 tables. So my problem is that I need to fetch all the records for one top category. For example if I want all the "I hate shirst" for dogs.

Desired result

I hate dogs
I hate chihuahuas
I hate brown chihuahuas
I hate black chihuahuas
I hate poodles

Thanks for your help

CREATE TABLE [category_cat] (
[id_cat] int IDENTITY NOT NULL,
[idcat_cat] int NOT NULL,
[name_cat] varchar(50) NOT NULL,
PRIMARY KEY CLUSTERED ([id_cat])
)

CREATE TABLE [product_pdt] (
[id_pdt] int IDENTITY NOT NULL,
[name_pdt] varchar(50) NOT NULL,
PRIMARY KEY CLUSTERED ([id_pdt])
)

CREATE TABLE [pdttocat_ptc] (
[id_ptc] int IDENTITY NOT NULL,
[idpdt_ptc] int NOT NULL,
[idcat_ptc] int NOT NULL,
PRIMARY KEY CLUSTERED ([id_ptc])
)


INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (1, 0, 'Dogs')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (2, 1, 'Chihuahua')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (3, 2, 'Brown')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (4, 2, 'Black')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (5, 1, 'Poodle')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (6, 0, 'Cats')

INSERT INTO [category_cat] ([id_cat], [idcat_cat], [name_cat])
VALUES (7, 6, 'Siamese')


INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (1, 'I hate dogs')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (2, 'I hate chihuahuas')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (3, 'I hate brown chihuahuas')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (4, 'I hate black chihuahuas')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (5, 'I hate poodles')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (6, 'I hate cats')

INSERT INTO [product_pdt (yannick_admin)] ([id_pdt], [name_pdt])
VALUES (7, 'I hate siamese')


INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (1, 1, 1)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (2, 2, 2)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (3, 3, 3)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (4, 4, 4)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (5, 5, 5)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (6, 6, 6)

INSERT INTO [pdttocat_ptc (yannick_admin)] ([id_ptc], [idpdt_ptc], [idcat_ptc])
VALUES (7, 7, 7)
Oct 19 '07 #1
0 1090

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jef Driesen | last post by:
I need some help to implement the adjacency list representation of a (undirected) graph. The data structure I need is something like the picture on the website...
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
12
by: Steve | last post by:
I have been studying the Adjacency List Model as a means of achieving a folder structure in a project I am working on. Started with the excellent article by Gijs Van Tulder ...
0
by: amodagni | last post by:
Hi ! Could someone please guide me to SQL code required for managing data in tables in which hierarchical data stored in adjacency or Nested set model.
2
by: sanjeevron | last post by:
Define a class for an adjacency matrix representation of weighted, directed graphs in C++. 2. Implement the following essential methods in your class. Any input validation or exceptions must be...
1
by: madhuparna | last post by:
Plzz give the code for implementing adjacency matrix in C
2
by: orzeech | last post by:
Here's my code that's supposed to be a basic graph implementation using adjacency lists. It comes straight from R.Sedgewick's "Algorithms in C++". However "23 - ISO C++ forbids declaration of...
0
by: kantai | last post by:
Need help in solving the problem below. Any help would be highly appreciated Implement the adt graph as a C++ class first by using an adjacency matrix to represent the graph then by using an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.