I have a work request:

SELECT * FROM `posts` WHERE `groupid` IN (SELECT groupid FROM grouplists WHERE `usid` = '$usid') AND reposts IN (SELECT reposts FROM grouplists WHERE `usid` = '$usid') 

It selects those lines where reposts is exactly the selected value, and I need it to select lines with a value greater than or equal to the selected one. How to do it?

Grouplists table posts table

    2 answers 2

    Without a visible structure is difficult, but it seems you can do without subqueries ...

     SELECT * FROM posts p JOIN grouplists g ON p.groupid=g.groupid WHERE g.usid = '$usid' AND p.reposts>=g.reposts 
    • I have something #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' =' 1 'AND p.reposts> = g.reposts` LIMIT 0, 50' at line 4 '. I updated the question. Hover over the pictures - the names of the tables are written there. - devtwo
    • an extra apostrophe was. Updated. Check my request again - cyadvert

    As I understand it, you need to fix the query something like this.

     SELECT * FROM `posts`WHERE `groupid` IN (SELECT groupid FROM grouplists WHERE `usid` = '$usid') AND reposts IN (SELECT reposts FROM grouplists WHERE `usid` >= '$usid') 

    Or use JOIN. Can you provide a table structure to figure out how to combine them?

    • No, WHERE usid = '$usid' is not that. I need that here - reposts IN (...) select a value greater than or equal to the value obtained in brackets. - devtwo
    • Corrected the answer. - OmBird
    • reposts IN - enter this value. You need to put> = instead of IN - binliz