php - Select multiple fields on different rows with ONE query -


with 1 mysql query only, how can check if buyer , seller have both bought each other ?

table : purchase

purchase_id     |   seller       |   buyer        12       |      2         |     5        29       |      5         |     2 

if query returns result (which case here), specific div appear on page.

select (count(*) >= 2) result   purchase        inner join purchase b          on a.seller = b.buyer ,             a.buyer = b.seller  (a.seller = 2 , a.buyer = 5) or        (a.seller = 5 , a.buyer = 2) 

just replace 2 , 5 variables.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -