Hi, mysqlsql code : SELECT oda.ad as odaad, musteri.ad, musteri.soyad, musteri.tckimlik, odaid, mid, rid, bakiyesanalFROM ( SELECT TBLTOPLAMLAR.odaid, TBLTOPLAMLAR.mid, rid, sum( bakiyesanal ) AS bakiyesanalFROM ( SELECT rezervasyon.odaid AS odaid, rezervasyon.musteriid AS mid, rezervasyon.id AS rid, ucret AS bakiyesanalFROM rezervasyonUNION ALL SELECT 0 , 0, extra.rezervasyonid AS rid, extra.ucret AS bakiyesanalFROM extraUNION ALL SELECT 0 , 0, tahsilat.rezervasyonid AS rid, (tutar * -1) AS bakiyesanalFROM tahsilat)TBLTOPLAMLARGROUP BY ridHAVING bakiyesanal <> 0)DISTOPLAMINNER JOIN oda ON oda.id = DISTOPLAM.odaidINNER JOIN musteri ON musteri.id = DISTOPLAM.mid PHP: but i am not add " where rezervasyon.gruprezervasyon=0" how to add code?
You have a union with an unequal number of fields and, I suspect, fields that aren't the same type in both parts of the union. As far as a WHERE clause, I don't understand your question. If you don't add it, it's not going to be there.
Then add the WHERE clause to the leg of the union you want it in. But the query will fail if a) there's a different number of columns in the two legs or b) the data types are different in the two legs. (IOW, if you SELECT varchar, varchar, integer in one leg, you can't SELECT integer, varchar, varchar in the other.) The fact that the code already exists doesn't mean that it works. (It might be returning no rows not because no rows match, but because there's an error and the code is hiding them.)