Toon posts:

[MySQL] foute SELECT query?

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hoi!

Ik heb een query'tje samengesteld in Access. Ik trek mbv Access de data uit een mysql databeest.

in Access werkt deze query gewoon en krijg ik keurig alle data te zien. Als ik deze code echter mbv PHP (of phpmyadmin) of de database loslaat krijg ik een error. Kan iemand mij vertellen wat ik hier fout doe? En hoe ik dat kan oplossen? Thanx.
code:
1
2
3
4
5
6
7
8
9
10
11
SELECT tblForumMsg.MsgID, tblForumMsg.MsgTitel, tblForumMsg.MsgDateTime, tblForumTopic.TopicID, tblForumTopic.TopicTitel AS Forumnaam, tblForumUser.UserNickName AS Gebruikersnaam, Count(tblForumReply.ReplyID) AS AantalReplies
FROM tblForumReply 
INNER JOIN ((tblForumMsg INNER JOIN tblForumTopic ON tblForumMsg.MsgBelongsTo = tblForumTopic.TopicID) INNER JOIN tblForumUser ON tblForumMsg.MsgPoster = tblForumUser.UserID) ON tblForumReply.ReplyTo = tblForumMsg.MsgID
WHERE (((tblForumMsg.MsgTitel) Like 'test%'))
GROUP BY tblForumMsg.MsgID, tblForumMsg.MsgTitel, tblForumMsg.MsgDateTime, tblForumTopic.TopicID, tblForumTopic.TopicTitel, tblForumUser.UserNickName
ORDER BY tblForumMsg.MsgDateTime DESC;


MySQL retourneerde: 

You have an error in your SQL syntax near '((tblForumMsg INNER JOIN tblForumTopic ON tblForumMsg.MsgBelongsTo = tblForumTop' at line 2

Verwijderd

Ik tel een ) te weinig

en das vast in dit stuk:
WHERE (((tblForumMsg.MsgTitel) Like 'test%'))

Verwijderd

Topicstarter
Jah?

ik niet hoor :)

in de joins worden er 2 geopend en 2 gesloten..
en in de where 3

zou het kunnen zijn dat access de code "vertaalt" ofzo voordat hij naar de mysql database gestuurd wordt?

Niemand die iets fout ziet?

  • robjanssen
  • Registratie: September 2001
  • Laatst online: 02-08 16:10

robjanssen

Software Developer

Laat alle haakjes () eens weg!!!

Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SELECT 
    tblForumMsg.MsgID, tblForumMsg.MsgTitel, tblForumMsg.MsgDateTime, tblForumTopic.TopicID,     tblForumTopic.TopicTitel AS Forumnaam, tblForumUser.UserNickName AS Gebruikersnaam,     Count(tblForumReply.ReplyID) AS AantalReplies
FROM 
    tblForumReply
INNER JOIN (
        (
            tblForumMsg INNER JOIN tblForumTopic ON tblForumMsg.MsgBelongsTo = tblForumTopic.TopicID
        )
        INNER JOIN tblForumUser ON tblForumMsg.MsgPoster = tblForumUser.UserID
     ) 
    ON tblForumReply.ReplyTo = tblForumMsg.MsgID
    WHERE (
        (
            (
                tblForumMsg.MsgTitel) Like 'test%'
            )
        )
GROUP BY 
    tblForumMsg.MsgID, tblForumMsg.MsgTitel, tblForumMsg.MsgDateTime, tblForumTopic.TopicID,     tblForumTopic.TopicTitel, tblForumUser.UserNickName
ORDER BY 
    tblForumMsg.MsgDateTime 
DESC;

1 haakje te weinig sowieso

Verwijderd

Ik tel in totaal 12 haakjes, dus dat zit wel goed.

Verwijderd

Topicstarter
Want zelfs als ik alle haakje weghaal lukt het nog niet.
De foutmelding begon toen ik de count had toegevoegd. Maar daar mág het toch niet aan liggen?

kutzooi... Kan het niet zo zijn dat ACCESS de code "vertaalt" ofzo voordat hij hem naar de mysql-database stuurt. Dus dat hij de code "mysql-compatible" maakt ofzo?

of lul ik nu onzin?

Verwijderd

Topicstarter
Op vrijdag 01 februari 2002 08:04 schreef DarthRaider het volgende:
1 haakje te weinig sowieso
achter tblForumMsg.MsgTitel in het WHERE gedeelte stond nog een haakje :0

Verwijderd

Topicstarter
Niemand die een oplossing ziet?

  • whoami
  • Registratie: December 2000
  • Laatst online: 23:14
Ik denk dat het te maken heeft met die stomme join syntax. Begrijpt MySQL dat soort joins met die INNER JOIN dinges enzo?

join eens gewoon zo:
code:
1
WHERE table1.PK = table2.FK

enzo.

https://fgheysels.github.io/


Verwijderd

Probeer het FROM statement zo eens:
code:
1
2
3
4
FROM tblForumReply 
INNER JOIN tblForumMsg ON tblForumReply.ReplyTo = tblForumMsg.MsgID
INNER JOIN tblForumTopic ON tblForumMsg.MsgBelongsTo = tblForumTopic.TopicID
INNER JOIN tblForumUser ON tblForumMsg.MsgPoster = tblForumUser.UserID

Verwijderd

Topicstarter
Damn, GentleMan... You're good!

Access slikt het nu niet meer.... so what! Mijn mysql databeestje lijkt er wel blij mee te zijn :)


It's working!


Bedankt :)

  • whoami
  • Registratie: December 2000
  • Laatst online: 23:14
Ik denk dat als je:
code:
1
2
3
4
FROM tblForumReply, tblForumMsg, tblForumReply, tblForumTopic, tblForumUser
WHERE tblForumMsg.MsgID = tblForumReply.ReplyTo
AND   tblForumTopic.TopicId = tblForumMsg.MsgBelongsTo
AND   tblForumUser.UserId = tblForum.Msg.MsgPoster

doet, zowel Access als MySQL het zullen slikken.

Mind eventuele syntaxfouten of tables die ik vergeten ben.

https://fgheysels.github.io/


Verwijderd

No sweat! 8-)
Pagina: 1