Dismiss Notice
You are browsing this site as a guest. It takes 2 minutes to CREATE AN ACCOUNT and less than 1 minute to LOGIN

Msaada MySQL

Discussion in 'Tech, Gadgets & Science Forum' started by MkamaP, Sep 10, 2009.

  1. M

    MkamaP JF-Expert Member

    #1
    Sep 10, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    nimejaribu kuandika kitu hiki

    SELECT *
    FROM klienci
    WHERE EXISTS (

    SELECT adres
    FROM klienci
    WHERE id = '1'
    )
    nimejaribu kubadili sana lakini wapi na tatizo mie sioni ,naomba msaada haswa wa kutumia exists.

    code hiyo hapo juu napata ERROR hii:


    #1064 - Something is wrong in your syntax obok 'exists (select adres from klienci where id = '1') LIMIT 0, 30' w linii 1
    Mwenye kuona tatizo nisaidie ama kuna namna ya kutumia EXIST?
     
  2. P

    Papizo JF-Expert Member

    #2
    Sep 10, 2009
    Joined: Feb 24, 2008
    Messages: 4,237
    Likes Received: 138
    Trophy Points: 160
    Mkubwa nadhani hiyo kitu huwa inaumiza sana kichwa....Kama una file la hiyo kitu basi mimi naona delete then install again hapo ndio utajua tatizo litakuwa wapi ila kusolve hivyo kama unavyotaka wewe nadhani inabidi ucheze sana na database na sio rahisi!!
     
  3. GP

    GP JF-Expert Member

    #3
    Sep 10, 2009
    Joined: Feb 5, 2009
    Messages: 2,076
    Likes Received: 7
    Trophy Points: 135
    MySql ya mwaka upi unatumia, na front end unatumia ipi?
    coz wakati mwingine inategemeana na version ipi unatumia ya MySql vs front end.
    tukija kwenye jinsi ya kutumia EXISTS:

    SELECT *
    FROM klienci
    WHERE EXISTS (

    SELECT adres
    FROM klienci
    WHERE id = '1'
    )

    kwanza kabisa hii query itaanza kua executed kwenye mabano:
    (
    SELECT adres
    FROM klienci
    WHERE id = '1'
    )
    then baada ya kuona kwamba query inareturn rows ndio itakwenda kwenye EXISTS condition.
    kwamfano ikiwa query hii ikakupa result, then EXISTS condition itakua executed na itareturn rows zote kutoka kwenye table ya klienci.

    kwamahesabu ya haraka haraka nadhani utakua umekosea kwenye datatype. naitilia mashaka hiyo column ya id, inaweza ikawa umedeclare as integer lakini hapa umeandika as 'varchar' cheki hapa: WHERE id = '1'

    hebu jaribu kutumia hizi data hapa chini kwenye mysql yako kisha unijuze kama umepata result ama vipi, nimejaribu kutumia simple query inayofanana na yako.
    ukipata result then jaribu kucompare na query yako uone tatizo likwapi.
    JUST COPY AND PASTE INTO QUERY ANALZER AND RUN IT.


    CREATE TABLE Books
    (
    BookID SMALLINT NOT NULL PRIMARY KEY,
    BookTitle VARCHAR(60) NOT NULL,
    Copyright varchar(10)
    )

    INSERT INTO Books VALUES (12786, 'Java',1934)
    INSERT INTO Books VALUES (13331, 'MySQL',1919)
    INSERT INTO Books VALUES (14356, 'PHP',1966)
    INSERT INTO Books VALUES (15729, 'PERL',1932)
    INSERT INTO Books VALUES (16284, 'Oracle',1996)
    INSERT INTO Books VALUES (17695, 'Pl/SQL',1980)
    INSERT INTO Books VALUES (19264, 'JavaScript',1992)
    INSERT INTO Books VALUES (19354, 'Vb.NET', 1993)

    RKisha malizia kwa run hii query hapa chini

    SELECT *
    FROM books
    WHERE EXISTS (
    SELECT bookid
    FROM books
    WHERE bookid = 12786
    )




     
    Last edited: Sep 10, 2009
  4. M

    MkamaP JF-Expert Member

    #4
    Sep 10, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Nafikiri version ni 3.13.58 kitu ka hicho maana saizi sipo home nikirudi nitacheck sawa.Lakini nafikiri ni hiyo.
     
  5. M

    Manitoba JF-Expert Member

    #5
    Sep 10, 2009
    Joined: Jul 8, 2008
    Messages: 240
    Likes Received: 2
    Trophy Points: 0
    EXIST haiko suported na version za MySQL < 4.1 . Jaribu ku-upgrade utumia latest MySQL version.

    Sina uhakika unajaribu kufanya nini, lakini pengine hii inaweza kufanya unachotaka kufanya hapo:

    SELECT a.* FROM klienci as a
    LEFT JOIN klienci as b
    WHERE b.id='1' AND b.id IS NOT NULL
     
  6. M

    Manitoba JF-Expert Member

    #6
    Sep 10, 2009
    Joined: Jul 8, 2008
    Messages: 240
    Likes Received: 2
    Trophy Points: 0
    Pia sub-queries hasipo supported kwenye MySQL < 4.1

    Kwa hiyo kama unataka kutafuta "klienci" zenye same address, kwa mfano, huwezi kufanya kitu kama hichi pia:

    SELECT a.*, c.*
    FROM klienci as a
    LEFT JOIN (SELECT * FROM klienci) as b on(a.adres=b.adres)
    WHERE a.id<>b.id
     
    Last edited: Sep 13, 2009
  7. M

    MkamaP JF-Expert Member

    #7
    Sep 11, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Mkuu bado tatizo liko pale pale
     
  8. M

    MkamaP JF-Expert Member

    #8
    Sep 11, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Mkuu asante nafikiri pia tatizo ni version.

    Nachotaka kufanya ni ,mfano kunakuwa na table la data za mteja na table la oder za mteja,hivyo sitaki kuingiza redandati data za mteja,hivyo nachotaka kufanya ni inacheck kama huyo mteja ana exist basi i update order table tu na kama ha exists i update table zote.ktk shema
     
    Last edited: Sep 11, 2009
  9. Zakumi

    Zakumi JF-Expert Member

    #9
    Sep 11, 2009
    Joined: Sep 24, 2008
    Messages: 4,574
    Likes Received: 11
    Trophy Points: 135
    Nime data structure ya table yako na kile unachotaka kufanya na nitafanya simulation sasa hivi.
     
  10. M

    Manitoba JF-Expert Member

    #10
    Sep 13, 2009
    Joined: Jul 8, 2008
    Messages: 240
    Likes Received: 2
    Trophy Points: 0
    Nadhani solution nzuri ni kufanya hili nje ya MySQL. Kabla huja insert new order, check kama client yupo tayari.

    Kama yupo, perform a query kupata id ya client huyo, e.g. select client_id from client where client_name='Client name kutoka kwenye form'. Kama hayupo, insert client kwanza na tumia mysql_insert_id kupata id ya huyo client mpya.

    Baada ya kuwa na id ya client, unaweza sasa ku insert hiyo order yako, ukiwa umeweka client_id field ya order hiyo sawasawa.

    Unatumia programming language gani?
     
  11. M

    MkamaP JF-Expert Member

    #11
    Sep 13, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Mkuu nasubiri hiyo kitu
     
  12. M

    MkamaP JF-Expert Member

    #12
    Sep 13, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Mkuu nashukuru kwa maelekezo yako murua,nilitoka kidogo .

    Nina swali jingine hapa.
    mfano ktk table yangu na attribute hizi-
    ,type _of_product,vendor_name, model.Sasa hapa nataka quel ambayo itatoa bidhaa zote(type_of_product) kutoka kwa ma vendor wote.na kila product iwe na attribute yani ,type _of_product,vendor_name, model, na product zijipange kutokana na type_of_product according to vendor_name.

    Mkuu natumia PHP
     
    Last edited: Sep 13, 2009
  13. Zakumi

    Zakumi JF-Expert Member

    #13
    Sep 13, 2009
    Joined: Sep 24, 2008
    Messages: 4,574
    Likes Received: 11
    Trophy Points: 135

    MkamaP:

    Kutokana na posti yako ya kwanza, database parser ime-respond kuwa kuna syntax error. Syntax error inaonyesha kuwa umekosea kuandika query yenyewe. Hivyo inawezekana sio tatizo la version.

    Sasa tuje kwenye uchambuzi wa SQL statement. Kumbuka kuwa database table ni set. Na queries ni instanties za table.

    Statement hii SELECT * FROM klienci ni query inayorudisha instant au temporary table yenye data structure sawa na table klient.

    Statement SELECT adres FROM klienci ni query yenye kurudisha instant au temporary table yenye data structure tofauti na table klient. Hii ni new table yenye column moja tu inayoitwa adres. Hivyo kuna uwezekano mkubwa kuwa database engine inashindwa kulinganisha table klienci na temporary table yenye column moja tu.

    Hivyo ningeomba ujaribu:

    SELECT *
    FROM klienci
    WHERE EXISTS (
    SELECT *
    FROM klienci
    WHERE id = '1'
    )

    Select statement iliyo ndani ya mabano ina data structure sawa na table klienci iliyopo nje. Sijuhi kama hii itasaidia.
     
  14. M

    MkamaP JF-Expert Member

    #14
    Sep 13, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180

    Mkuu wangu angalia majibu kitu hakitaki
    SQL-query: [​IMG]

    SELECT *
    FROM klienci
    WHERE EXISTS (
    SELECT *
    FROM klienci
    WHERE id = '1'
    )
    LIMIT 0 , 30

    MySQL said: [​IMG]
    #1064 - Something is wrong in your syntax obok 'EXISTS (
    SELECT *
    FROM klienci
    WHERE id = '1'
    ) LIMIT 0, 30' w linii 4
     
  15. Zakumi

    Zakumi JF-Expert Member

    #15
    Sep 14, 2009
    Joined: Sep 24, 2008
    Messages: 4,574
    Likes Received: 11
    Trophy Points: 135
    Mkamap:

    Inabidi ni-backtrack niliyosema mwanzo. Katika ku-execute Exists mySQL uwa ina-ignore colums za select zilizopo after Exists. Hivyo select zilizokuwepo chini zinatakiwa kufanya kazi sawa kweny query yako.

    SELECT * FROM klienci WHERE id = '1'
    SELECT adres FROM where klienci id = '1'
    SELECT 1 FROM klienci WHERE id = '1'


    However, Exists imeanza kutumika baada ya version 4.1. Hii hapa ni respond niliyopata kutoka mySQL:


    EXISTS is supported from 4.1 on. Earlier versions of MySQL can try rewriting the query using a LEFT JOIN.

    Hivyo base angalia version ya server yako kama ilivyoagizwa na wachangiaji wengine.

    Pamoja na hayo EXISTS ni technology specific command. Lakini problem unayotaka ku-solve inaweza kuwa solved standard database commands.
     
  16. M

    Manitoba JF-Expert Member

    #16
    Sep 14, 2009
    Joined: Jul 8, 2008
    Messages: 240
    Likes Received: 2
    Trophy Points: 0
    Du! Sina uhakika kama nimekuelewa.

    Ku select data kutoka kwenye table inayoitwa "product" yenye columns type _of_product,vendor_name, model ni kama ifuatavyo:
    SELECT type _of_product,vendor_name, model
    FROM product

    Ukitaka zijiange kuenda na type_of_product ongezea ORDER BY type_of_product, kama hivi:
    SELECT type_of_product,vendor_name, model
    FROM product
    ORDER BY type_of_product

    Na ukitaka zijipange kuendana na vendor_name:
    SELECT type_of_product,vendor_name, model
    FROM product
    ORDER BY vendor_name

    Na ukitaka zijipange kuendana na type_of_product , na pale type_of_product zinapofanana zijipange kuendana na vendor_name
    SELECT type_of_product,vendor_name, model
    FROM product
    ORDER BY type_of_product, vendor_name


    Jifunze kidogo basics za SQL,
    http://www.w3schools.com/sql/default.asp
     
  17. JuaKali

    JuaKali JF-Expert Member

    #17
    Sep 15, 2009
    Joined: Nov 14, 2007
    Messages: 783
    Likes Received: 0
    Trophy Points: 33
    Error 1064 = Version mismatch!!!
    download mysql mpya, tena angalia version ya PHP inayoendana na Mysql otherwise utashinda nalo usiku kucha. Nimewahi kupata tatizo kama lako, tulikuwa na project shule kutumia PHP - scripting, Apache = Server, Mysql = Database, Phpmyadmin. Nilipokuwa na download Apache kumbe nimechukua ile isiyoendana na Mysql jasho likanitoka.
     
  18. M

    MkamaP JF-Expert Member

    #18
    Sep 15, 2009
    Joined: Jan 27, 2007
    Messages: 6,471
    Likes Received: 469
    Trophy Points: 180
    Nawashukuruni nyote
     
Loading...