Erreur LIMIT lors de l'exécution de la requête
P粉668146636
P粉668146636 2024-03-27 12:26:04
0
1
407

C'est la requête que j'ai essayé d'écrire

select posts.*  ,users.* 
FROM posts
INNER JOIN users
   ON posts.user_id = users.id
   WHERE posts.user_id != '27'
   AND posts.pid EXISTS(SELECT post_id FROM favourites WHERE posts.pid=favourites.post_id)

C'est une erreur

select posts.*  ,users.* 
FROM posts
INNER JOIN users
   ON posts.user_id = users.id
   WHERE posts.user_id != '27'
   AND posts.pid EXISTS(SELECT post_id FROM favourites WHERE posts.pid=favourites.post_id) LIMIT 0, 25
MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXISTS(SELECT post_id FROM favourites WHERE posts.pid=favourites.post_id) LIM...' at line 6

P粉668146636
P粉668146636

répondre à tous(1)
P粉276876663

Vous devez utiliser IN au lieu de ÈXISTS.

existe a une syntaxe différente

SELECT 
    posts.*, users.*
FROM
    posts
        INNER JOIN
    users ON posts.user_id = users.id
WHERE
    posts.user_id != '27'
        AND posts.pid IN (SELECT 
            post_id
        FROM
            favourites
        WHERE
            posts.pid = favourites.post_id)
LIMIT 0 , 25

Cela vérifiera s'il y a un identifiant de publication préférée

SELECT 
    posts.*, users.*
FROM
    posts
        INNER JOIN
    users ON posts.user_id = users.id
WHERE
    posts.user_id != '27'
        AND EXISTS (SELECT 
            post_id
        FROM
            favourites
        WHERE
            posts.pid = favourites.post_id)
LIMIT 0 , 25
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal