2
2
2bastu32015-03-17 14:36:40
SQL
2bastu3, 2015-03-17 14:36:40

Table structure for data like this?

Interested in how to relationally store expressions like
((a or b) and (c or d) and e) or f
where a, b, c .. some rows from a table with some primary key (let's say id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Ovchinnikov, 2015-07-06
@ova777

I propose a table with the following structure:

CREATE TABLE IF NOT EXISTS `expressions` (
  `id` int(10) unsigned NOT NULL,
  `rel_a` enum('self','external') NOT NULL,
  `id_a` int(10) unsigned NOT NULL,
  `operation` enum('and','or') NOT NULL,
  `rel_b` enum('self','external') NOT NULL,
  `id_b` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Where one entry is one operation between two entities.
An entity can be either a record with an id from an external table (rel=external) or an id from the current one (rel=self).
Let's break down your expression. way
Entries in the table:
where A, B, C, D, E, F are the IDs of the records from the external table
The record with ID=5 will be your original expression.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question