hoe krijg ik deze query werkend?
"SELECT COUNT(reactionid) AS total FROM event_comments, members WHERE eventid = 1 AND reactionid NOT IN(INSERT(event_comments_read, LENGTH(event_comments_read), 1, '')) AND id = 1";
het gaat hierom:
ik heb 2 tabellen, 1 geheten members en 1 geheten event_comments
alle rijen in event_comments hebben een id (reactionid)
als zo'n reactie is gelezen, wordt dit id opgeslagen in de leden tabel in het vakje event_comments_read (op deze manier 1,2,3,4,5,), id is het id van de gebruiker
het gaat fout bij dit stukje IN(INSERT(event_comments_read, LENGTH(event_comments_read), 1, ''))
dit moet dus worden IN(1,2,3,4,5), zonder de laatste komma
als ik de waarden gewoon in de query invul werkt de query correct
kan dit wel zo? of kun je INSERT en LENGTH alleen maar bij SELECT gebruiken?
alvast bedankt voor de hulp!
Gewijzigd op 01/01/1970 01:00:00 door Ron -
"Werkt niet" is nogal breed ;).
Ook zie ik geen GROUP BY oid, wat vaak wel nodig bij een COUNT().
Tevens VERMOED ik dat een NOT IN(INSERT ...) niet echt werkt.
NOT IN(SELECT ...) werkt daarintegen weer wel.
En volgens mij is je INSERT-code oko niet werkend, of geef je nu direct 1 kolom op met daarachter 1 waarde (en dan nog een 1 en een NULL)?
de bedoeling is om 1,2,3,4,5, op te halen (event_comments_read)
daar de laatste komma vanaf te halen (1,2,3,4,5)
zodat je krijgt IN(1,2,3,4,5)
en dan alle reactionid's telt die hierin voorkomen
COUNT() werkt verder prima zo hoor
dit werkt ook niet:
"SELECT COUNT(reactionid) AS total FROM event_comments, members WHERE eventid = 1 AND reactionid NOT IN(SELECT INSERT(event_comments_read, LENGTH(event_comments_read), 1, '')) AND id = 1";
Quote:
INSERT(str,pos,len,newstr)
Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr. Returns the original string if pos is not within the length of the string. Replaces the rest of the string from position pos if len is not within the length of the rest of the string. Returns NULL if any argument is NULL.
Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr. Returns the original string if pos is not within the length of the string. Replaces the rest of the string from position pos if len is not within the length of the rest of the string. Returns NULL if any argument is NULL.
Daar zit dus je fout.
COUNT werkt inderdaad zo, ik was even in de war met JOINS etc.
De INSERT hoort dus gewoon NIET in deze query.
ik heb het nu opgelost door het in 2 querys te doen