relational

In SQL, how do you get the top N rows ordered by a certain column?

I want to select the top N rows of a table, ranked by how high the number in one of their columns is. I already have: SELECT * FROM movie ORDER BY worldwide_gross DESC; How can I get the first twenty? If it makes any difference I'm using MySQL. Cheers! ...

How do I represent object classification hierarchy in a RDBMS

My data, IF it would be represented by objects, it would look like: abstract class A{ int a; int b; string c; } class B inherits A{ string D; } class C inherits A{ int e; int f; } My question: Do I create a separate table for entities B and C, Or do I create one main table, and for each entity type I do different joi...

Graph Edges Rails

I found this recently when trying to do bidirectional relationships in rails (http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/) class Befriending < ActiveRecord::Base belongs_to :initiator, :class_name => :User belongs_to :recipient, :class_name => :User after_create do |b| BefriendingEdge.create!(:user =...

How generate diagram from SQL DDL?

For example DbVisualizer can be used to connect to a DB and create nice diagram out of existing tables and their relations. But in this specific case I do not have a live database but I have bunch of create table and alter statements. Is there any tool to generate similar diagrams out of SQL DDL? ...

Ruby On Rails Relationships - One to Many

I'm a beginning to ROR, but here's what I'm trying to achieve. I have two items I want to associate: matters and people. Each matter can have many people. That is, I want to create people and matters separately and later be able to link them. For example, I may create: Bill Clinton Barack Obama I may create the matters: Global warming ...

Modeling atomic facts in a relational database

I want to record what various sources have to say about a historical figure. i.e. The website Wikipedia says that Susan B. Anthony was born February 15, 1820 and her favorite color was blue The book Century of Struggle says that Susan B. Anthony was born on February 12, 1820 and her favorite color was red The book History of Woman's S...

How to build a relational structure in javascript?

I have 2 tables in DB: 1- Element: ElementID ElementName 2- Methods: MethodID ElementID MethodData So there is a one to many relation between Elements and Methods, I load these tables data using asp.net, What i want to do is to send these data to my javascript, and javascript will do some functions on these data. For example ...

Effecient way to model aggregate data of a many-to-one relationship (e.g. votes count on a stackoverflow question)

I'm curious about what be the best way to model this for optimized performance... not as concerned about real time data integrity I'll continue with the stackoverflow example Question id title Votes id user question A question has many votes For many queries however, we're only concerned with the aggregate number of votes ...

SQL static data / lookup lists IDENTIFIER

In regard to static data table design. Having static data in tables like shown: Currencies (Code, Name). Row example: USD, United States Dollar Countries (Code, Name). Row example: DE, Germany XXXObjectType (Code, Name, ... additional attributes) ... does it make sense to have another (INTEGER) column as a Primary Key so that all For...

Dynamic Types within a Relational Model using Object-Role-Modeling (ORM)

In Object Role Modeling (ORM), given an entity of thing that had a relationship to an entity of type and where the type entity can be specified to live and the thing entity could have a value for date of birth, how would I specify a constraint that would exclude instances of thing from having a value for date of birth if the instance of ...

Are there any examples of Functional Relational Programming in the wild?

I've just finished reading a very interesting paper entitied "Out of the Tar Pit" which presents this idea of FRP as a way of reducing complexity in applications by minimizing state and control. Are there any examples of this idea out in the wild? Is anybody making use of these ideas? Is there any work being done in this area? Edit: FRP...

Relational Database

Can you do more than one clause in SQL without using aggregation and only: selection, join? Thanks. ...

Advantages of keeping to a protocol for a data model

Hi all, The question title is probably not correct because part of my question is to try and get some more understanding on the problem. I am looking for the advantages of making sure data that is imported to a database (simple example: Excel table to Access database) should be given using the same schema and should also be valid to th...

Achieving Fast Lookups for a Large Dataset: MySQL MEMORY(HEAP), Memcached, or something else

Currently working on a project that is centered around a medical nomenclature known as SNOMED. At the heart of snomed is are three relational datasets that are 350,000, 1.1 mil, and 1.3 mil records in length. We want to be able to quickly query this dataset for the data entry portion where we would like to have some shape or form of auto...

Retrieve maximal / minimal record

A rather complicated SQL query I was working on got me thinking about a limitation of (ANSI) SQL: Is there a way to retrieve a record that is maximal or minimal with respect to an arbitrary ordering? In other words: Given a query like this: SELECT * FROM mytable WHERE <various conditions> ORDER BY <order clause> is it possible to w...

Quick tips on relational database design for MySQL

Hi, I have a webapp I'm making that stores user information, and their preferences regarding the app. Is this something worth splitting into two databases? I was thinking one table "users" with fields "id, useridfromFacebook, facebookRealName" (so 1, 52052025295, Alex McP), and then have a table "preferences" with fields "id, useridfro...

Is this a textbook design pattern, or did I invent something new?

I'm fresh out of designing a set of tables, in which I came up with an architecture that I was very pleased with! I've never seen it anywhere else before, so I'd love to know if I've just reinvented the wheel (most probable), or if this is a genuine innovation. Here's the problem statement: I have Employees who can each sign a differen...

Combining Relational and Document based "Databases"

I am developing a system that is all about media archiving, searching, uploading, distributing and thus about handling BLOBs. I am currently trying to find out the best way how to handle the BLOB's. I have limited resources for high end servers with a lot of memory and huge disks, but I can access a large array of medium performance off...

Intelligent ways to maintain versioned copies of tables in a relational database (programming considerations?)

Greetings, Just a bit of backgroung information - I am currently working on a relatively large desktop-based requirements management utility, and have come across an issue for which I believe I know the solution, but am hesitant to implement without further thought. Basically, at anytime during the usage of this requirements management...

Django relation doesnt work?

I have the following in models: class Companies(models.Model): ComName = models.CharField(max_length=255) ComURL = models.CharField(max_length=1024,null=True) class Products(models.Model): PrName = models.CharField(max_length=255) PrCompany = models.ForeignKey(Companies) and the following in the template: {% i...