Hi all,

I have a trouble with multiple-column indexes, I will try to describe it
with an example.
Suppose I have a table like the following one:
+------------+------------+-------+-----------+
| id_example | x_uno          | x_due  | x_desc    |
+------------+------------+-------+-----------+
|          1 | 2004-01-01 |     2 | qweqe     |
|          2 | 2004-01-01 |     3 | qqqqqqqqq |
|          3 | 2004-01-01 |     4 | weqweqweq |
|          4 | 2004-01-02 |     1 | QWEQWE    |
|          5 | 2004-01-02 |     2 | AAAAA     |
|          6 | 2004-01-02 |     3 | aaaaa     |
|          7 | 2004-01-02 |     4 | aaaa      |
|          8 | 2004-01-03 |     2 | 0         |
|          9 | 2004-01-03 |     5 | qqqq      |
+------------+------------+-------+-----------+
where id_example is the Primary Key, and there is an Index on x_uno, x_due.
How can I write a query in order to select records using a combination of
columns x_uno and x_due?
I would like, for example, to get the records starting from row number 6
(without, of course, working with the primary key, where the numbers could
not necessarily be sorted as here):
+------------+------------+-------+-----------+
| id_example  | x_uno          | x_due | x_desc      |
+------------+------------+-------+-----------+
|          6 | 2004-01-02 |     3 | aaaaa     |
|          7 | 2004-01-02 |     4 | aaaa      |
|          8 | 2004-01-03 |     2 | 0         |
|          9 | 2004-01-03 |     5 | qqqq      |
+------------+------------+-------+-----------+
In fact, a select with the following syntax:
SELECT * FROM `example` where x_uno>=20040102 and x_due >= 3 ORDER BY x_uno
ASC, x_due ASC
does not return me row number 8 (as it is 2<3 on column x_due).
Of course I could use a new (redundant) column composed by the two ones, so
that I have:
+------------+---------------+----------+-------+-----------+
| id_example | x_composed     | x_uno      | x_due | x_desc    |
+------------+---------------+----------+-------+-----------+
|          6 | 20040102003 | 2004-01-02 |     3 | aaaaa     |
|          7 | 20040102004 | 2004-01-02 |     4 | aaaa      |
|          8 | 20040103002 | 2004-01-03 |     2 | 0         |
|          9 | 20040103005 | 2004-01-03 |     5 | qqqq      |
+------------+---------------+----------+-------+-----------+
Anyway, I would not like to choose such a solution, as this situation would
be frequent with the tables I am going to use.
Is there something I am missing with SQL syntax?

Thank you,

Rocco Castino
M.C.S. Computer & Software S.r.l.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to