Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is there any "set" database? For example Neo4j is a "graph" database. What I'm looking for is database which can be used to organize "items" into "sets" and then be able to query them with set operations. For example "items that are in set A and B but not in set C".

Or which one of current databases can efficiently do this data modeling?

Sets are not limited, they can be added/edited/removed as data, just like items or like links in a graph database. For example making a new set called D or Set2347 and add some item in it.

An example would be pages liked by users, where each page is a "set" which is liked by users as "items" it contained.

To clarify my question I would better quote Karl Bielefeldt comment:

The question isn't whether it's possible to use a relational database for this use case. Obviously it is. It's possible to use a relational database for a graph, but we have graph databases anyway which make working with graphs a lot easier. Asking if something similar exists for sets is not an unreasonable or unclear question, even if the answer happens to be no. Maybe people have some good ways to make working with sets on relational databases easier.

share|improve this question

closed as unclear what you're asking by Dan Pichelman, Jimmy Hoffa, World Engineer Aug 30 '13 at 19:37

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

How is that different from a relational database (Oracle, SQL Server, MySQL, PostgreSQL, DB2, etc.)? –  Justin Cave Aug 30 '13 at 2:37
SQL joins are set functions. They are already very efficient, if your database is properly indexed. SQL developers already work with sets-items data. What am I missing here? –  Robert Harvey Aug 30 '13 at 4:31
@JohnS They fit a particular need quite well (it isn't set operations). They've been around for quite some time - LDAP, TupleSpace. That these are still around show that there is a niche for them. You may find Martin Fowler's nosql articles useful reading and general bit on the relational model to understand where the applications of each fit well. –  MichaelT Aug 30 '13 at 4:56
@JohnS - I don't know exactly what you think is so unique about your 'sets', but it's almost guaranteed the basic problem you're trying to deal with has solutions in the "traditional" databases you dismiss so easily. My company's product, using bog-standard SQL Server, crosses & filters hundreds of millions or billions of raw data records with hundreds of thousands of reference elements. It's not real-time, but what kind of performance are you looking for with what data volumes? –  DaveE Aug 30 '13 at 5:28
Maybe it's about time you came up with a detailed, real-world scenario of what you're trying to do. While it seems obvious to you that tables are not a solution, it is not at all obvious to the rest of us who have been using tables (i.e. relational databases) for years to solve exactly the problems you've described so far. –  Robert Harvey Aug 30 '13 at 19:36

1 Answer 1

It sounds like you are describing a relational database (which accounts for the overwhelming majority of the market share in the database market-- Oracle, SQL Server, DB2, MySQL, PostgreSQL, etc.). Relational databases are based on set theory.

In Oracle, for example, if you have tables A, B, and C, your logic would simply be

(SELECT <<column list>>
   FROM a
 SELECT <<column list>>
   FROM b)
SELECT <<column list>>
  FROM c

There are other ways to write this SQL as well, this is just the most "set theory-ish" syntax.

share|improve this answer
Your edit doesn't really change anything. Sets can be added/edited/removed in a relational database also. –  Robert Harvey Aug 30 '13 at 2:53
@JohnS: You can debate the internal data structures or vocabulary all you want, but if it walks like a duck and quacks like a duck, it's a duck. –  Robert Harvey Aug 30 '13 at 3:11
@JohnS - I have read it now multiple times. I fail to see how it is asking how to translate requirements into a data model and a SQL statement. I fail to see how that edit changes anything about the question. Again, if you're asking for help crafting SQL statements, you'd need to move the question over to StackOverflow. And choose a database. And provide more details about your actual requirements rather than talking about multiple disparate hypotheticals. –  Justin Cave Aug 30 '13 at 4:02
@COMEFROM So, what is a "set database", other than a table holding the items, with unique ID, and then a "set" is another table with one column with unique values, which are IDs of the actual item table? –  hyde Aug 30 '13 at 18:47
@JohnS: Karl Bielefeld's comment does not make your question clearer, since most people here think any relational DB is also "enough of a set DB to solve most real-world set problems, especially the ones you gave as example so far". You should add some more information or - even better - an example what you expect from a "set" DB to be solved in a better manner than from a relational DB. –  Doc Brown Aug 30 '13 at 18:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.