1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Sql code don't add where

Discussion in 'MySQL' started by nrtszr, Jan 5, 2013.

  1. #1
    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?
     
    nrtszr, Jan 5, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    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.
     
    Rukbat, Jan 5, 2013 IP
  3. nrtszr

    nrtszr Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    this code More prewritten
    now requirement " where rezervasyon.gruprezervasyon=0"
     
    nrtszr, Jan 5, 2013 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    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.)
     
    Rukbat, Jan 5, 2013 IP