Questions tagged [self-referencing-table]

Refers to database tables with a column that is a foreign key to another column within the same table.

131 questions
0
votes
3 answers

Finding all children for multiple parents in single SQL query and Linq query

I need to SELECT query using LINQ and also SQL resulting as: ParentId Country State ChildId 1 India kerala 2 1 India TamilNamdu 3 5 Pakistan Kasagithan1 6 5 Pakistan …
0
votes
1 answer

Tables with the same structure and similar data

This is a question about best practice really. I am developing a system, where I will be collecting some measurements (call them HR and RR) and calculating average values of these measurements. Now for the user interface we are only intrested in…
Daniel Gruszczyk
  • 5,379
  • 8
  • 47
  • 86
0
votes
2 answers

Self-referencing table - how to get results as one table

I have a table like this Please forgive the column names they are driven by internal standards. What I would like to know is how to query this self-referencing table so the output is something like this: | PARENT REASON | CHILD REASON | |…
Nick Birke
  • 137
  • 2
  • 12
0
votes
1 answer

Mysql: update to create group of visit entries separated by no more than maxmium minutes

I have the following mysql table which records user visit times: I'd like to update visit_id so that a "visit" is a group of entries for the same user where no entry is more than 20 minutes after the previous, and the visit_id for each entry is the…
kenji359
  • 87
  • 1
  • 1
  • 7
0
votes
3 answers

Creating test load for self-referencing table

I have to do some SQL Server 2008 R2 performance testing and it would be very convenient to do it using only SSMS and SQL Server, without additional application support. One of the tests I have to do is querying a self-referencing table (tree-like…
0
votes
1 answer

Self referencing Entity in Hibernate with additional Columns

I wanna map these tables with Hibernate: CREATE TABLE user ( id VARCHAR(20), //some stuff PRIMARY KEY(id) ); CREATE TABLE friendship ( user1 VARCHAR(20), user2 VARCHAR(20), firstMeeting TIMESTAMP, //mb some…
0
votes
3 answers

mysql - php - Need to get only the latest record from a self referencing data

Hi, I need some help with SQL. Attached is the image of my table. If you see rootmessageid column there are 4 records of 99s. All these 4 makes one complete conversation. Similarly the 2 records of 119 makes an other conversation. 116, 117, 118…
Farid Siddiqui
  • 165
  • 2
  • 2
  • 13
0
votes
3 answers

Kohana 3.3 ORM - how to find all ancestors in a tree (self-referencing table)

How to find all the ancestors (not only direct parent) of a record with the following model: class Model_Category extends ORM { protected $_belongs_to = array( 'parent' => array('model' => 'Category', 'foreign_key' =>…
Petrunov
  • 754
  • 1
  • 8
  • 18
0
votes
1 answer

Rearranging the tree nodes and saving it back on a self-referencing table with EF

I have a self-referencing table structure working fine with EF, which I use to render a tree view. The EF entity looks like the following and I eagerly load the total structure. class ListItem { int Id; string Text; ListItem ParentItem; …
0
votes
1 answer

Client\Supplier Contact Details

I was wondering what would be the best way to store contact details of supplier and clients. What I was thinking was that there would be GUID, ParentGUID,Type,TypeDesc,Details The type would be a integer,typedesc would be for cases such as others…
Enzero
  • 1,141
  • 2
  • 17
  • 36
-2
votes
1 answer

Create view from mysql self referential table and another table

I have a table 'organization' with fields id and parent. parent refers to the same table (self referential key). I have another table called 'user_organization', in which I have user_id and org_id. org_id is linked to id in 'organization' table. Now…
Harikrishnan
  • 3,664
  • 7
  • 48
  • 77
1 2 3
8
9