Hi listers
mysql> show global variables like "version";
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| version       | 5.1.46 |
+---------------+--------+
1 row in set (0.02 sec)

mysql>

Following problem: Two tables which must be joined differently depending on the contents of the second table,

the first table esentially contains a date field named datum.

the second table is as follows:

mysql> describe schulung;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| sdat     | date             | YES  |     | NULL    |                |
| tag      | text             | YES  | MUL | NULL    |                |
| szeit    | time             | YES  |     | NULL    |                |
| speziell | text             | YES  |     | NULL    |                |
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
+----------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql>

Now, if the second table in the sdat field contains a value which is equivalent to the datum field in the first table (datum = sdat), then this join must be taken and nothing else. Otherwise the more general join via the tag field must be taken (dayname(datum) = tag).

I tried to program this using not exists in the on clause of a join

.... inner join schulung on (if not exists (select sdat from schulung where sdat = datum) then (datum = sdat)) else dayname(datum) = tag)....

but I got an ERROR 1064 near 'not exists (select sdat ....'

Probably, I have to re-structure the entire statement to an other form using other constructs? Has anyone had similar problems? How did you solve it then?

Thank you very much.

suomi

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to