Hi,
Table "mpprim" has UNIQUE constraint on 3 fields: Primka, Tip, Godina (Document, Type, Year in English). I am trying to insert a new record into it without having first to count how manny documents of certain type exist in table for choosen year.


Sample data:
ID(Autoinc) Primka(INT not null) Tip(ENUM("D","M",..) Godina(YEAR)
        1       1                       "D"           2004
        2       2                       "D"           2004
        3       1                       "M"           2004
...

When I do
  SELECT IFNULL(MAX(Primka),0)+1 AS Primka
  FROM mpprim
  WHERE Godina = 2004
  AND Tip = "M"
  group by Godina

I don't get ANY result if there isn't at least one row with Type set to "M" in choosen year.
Is there a way to make this work?


Tonci Grgin
ARTRONIC d.o.o.

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



Reply via email to