Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
mysql pitanje

 
Post new topic   Reply to topic    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
Filip



Joined: 12 Jan 2008
Posts: 19

PostPosted: 05.08.2012 10:49    Post subject: mysql pitanje Add user to your forum ignore list Reply with quote

Kako se koristi not exists, jer recimo ova dva upita po meni trebala bi vracati isti rezultat, ali prvi vraca npr. 5 redaka, a drugi 0. U čemu griješim

-> ovaj radi
SELECT id_cat FROM izbornik WHERE id_cat NOT IN ( SELECT id_cat FROM kategorija )

->ovaj ne radi onako kako bi trebalo
SELECT id_cat FROM izbornik WHERE NOT EXISTS (SELECT id_cat FROM kategorija)

-> ovaj ne radi onako kako bi trebalo
SELECT id_cat FROM izbornik WHERE NOT EXISTS (SELECT id_cat FROM kategorija WHERE izbornik.id_cat = kategorija.id_cat)
Back to top
View user's profile Send private message
hrvoje_86



Joined: 06 Dec 2006
Posts: 107
Location: Zagreb

PostPosted: 05.08.2012 11:26    Post subject: Add user to your forum ignore list Reply with quote

Nije isto NOT IN je true ako se trenunti ID ne nalazi u sub query-ju a NOT EXISTS vraća true ako ti subquery vrati bilo kakve rezultate.

Znači exist koristiš da bi provjerio dali postoji neki unos u bazi npr korisnik sa nekim imenom.

RTFM Smile
http://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html

Quote:
If a subquery returns any rows at all, EXISTS subquery is TRUE, and NOT EXISTS subquery is FALSE. For example:


Code:

SELECT column1 FROM t1 WHERE EXISTS (SELECT * FROM t2);
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Filip



Joined: 12 Jan 2008
Posts: 19

PostPosted: 05.08.2012 12:48    Post subject: Add user to your forum ignore list Reply with quote

hvala hrvoje_86

ma gledao sam ja manual, ali to meni nije jasno

Quote:
Nije isto NOT IN je true ako se trenunti ID ne nalazi u sub query-ju a NOT EXISTS vraća true ako ti subquery vrati bilo kakve rezultate.


hmm ovo je zanimljivo, true za bilo koji rezultat od pod upita, to mi se čini bezveznim

svejedno hvala na pojašnjenju nisam nikad prije koristio exist pa sad vidim i zašto

izgleda da sam krivo dozivio tu naredbu exist Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group