Question: ```
class Node:
  def __init__(self, data = None, next = None):
    self.data = data
    self.next = next

class LinkedList(Node):
  def __init__(self, l_size = 0, head = None, tail = None):
    Node.__init__(self)
    self.l_size = 0
    self.head = head
    self.tail = tail

  def add(self, data):
    n = Node(data, None)
    if(self.l_size == 0):
      self.head.next = n
      self.head.data = n.data
    else:
      self.tail.next = n
      self.tail.data = n.data
      n = n.next
      print(n)
    self.tail = n 
    self.l_size += 1
    return True

l = LinkedList()
l.add(7)
l.add(8)
l.add(2)

```

I'm just trying to achieve `(h)-> 7 -> 8 -> 2 <- (l)`
Where (h) and (l) are the head and tail pointers respectively. The way I'm implementing this the LL is basically the head and the tail pointers, the Nodes chain together on their own, that's why I made Node a super class.

Answer: 
Simply aggregate your table per `user_id` and use `HAVING` to ensure both conditions are met for the user.

```
select user_id
from settings
group by user_id
having count(case when token = 'language' and value = 'en' then 1 end) > 0
   and count(case when token = 'newsletter' AND value = 1 then 1 end) > 0

```

You can add a `WHERE` clause to speed this up, if you like:

```
where (token = 'language' and value = 'en') or (token = 'newsletter' AND value = 1)

```
Please try This query :

```
SELECT user_id 
FROM settings 
WHERE  (token = 'language' AND value = 'en')
        OR  (token = 'newsletter' AND value = '1') 

```

There is no use of Group By clause