473,387 Members | 1,834 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,387 software developers and data experts.

Two table columns refer to one primary key problem

228 100+
Ola,

Am having problem with this design. I have tableTips (tipid (tipid (Primary, auto number),tipname). And another table tableRelatedTips (tipid1,tipid2).

Both tipid1 and tipid2 refer to tableTips. A combination of both must be unique. So when I am seeing tipid from tableTips, I want to see related tips.

Data Wise:

1 Tip 100
2 Tip 200
3 Tip 300
4 Tip 400

And tableRelatedTips

1 3 (1 and 3 are related)
2 1 (2 and 1 are related)

Is my design bad? How can I get list of related tips for a specific tip? E.G. if tip 1, I need to get tips 3 and 2.

I tried both IN and EXISTS (and NOT EXISTS) but I end up getting twice the row numbers in tableTableTips or none at all.

Any tips?
Feb 19 '15 #1
1 789
Rabbit
12,516 Expert Mod 8TB
Given that we have no idea what you're using the data for, or what it's supposed to represent, the design looks fine.

To find the ones that have 1 in either field, you can query exactly that in the WHERE clause.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tableRelatedTips
  3. WHERE
  4.    tipid1 = 1 OR
  5.    tipid2 = 1
If that's not what you're looking for, then you will need to explain more clearly what it is you're trying to achieve.
Feb 19 '15 #2

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

Similar topics

9
by: Bob C. | last post by:
I want to create a 1-many relationship. Parent table has a primary key, child table has no primary key. The child table does have an index with all four fields of the parent's PK. How can I do...
11
by: suma | last post by:
Hello, I want to delete duplicate rows in a table when no primary key is defined. For eg: If we have table1 with data as below, Suma 23 100 Suma 23 100 I want to delete a row from this...
4
by: serge | last post by:
I ran into a table that is used a lot. Well less than 100,000 records. Maybe not a lot of records but i believe this table is used often. The table has 26 fields, 9 indexes but no Primary Key at...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
4
by: VA | last post by:
There are a lot of excellent drag-n-drop Javascript libraries available out there http://script.aculo.us/ http://www.walterzorn.com/dragdrop/dragdrop_e.htm...
17
by: Romulo NF | last post by:
I´ve seen some people around the web wondering about a code to reorder table columns using the mouse (drag and drop). Since i had already made one script to reorder table lines (TR´s) i decided to...
2
by: Jacksm | last post by:
How can I align an asp:table columns with gridview columns (the widths)? I have tried setting table.column(0).width = gridview.column(0).width at page_load but it doesn't work. Thanks in advance
0
by: negmat | last post by:
Guys, Does SQL Server allow for creating conditional constraints on the table columns? My table is: CREATE TABLE ( IDENTITY (1, 1) NOT NULL ,
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
3
by: Pauke | last post by:
I want to add a primary key to a table with some duplicates and I have to get rid of them first, keeping the first row from each duplication case. Say I found a case of duplication where there are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.