I have a table and I need to write a SQL to limit the resulset set based on 2 conditions, by IP and out of that resultset, remove the rows which have nothing in 2 columns.

So I have tried this but it's not producing the expected results:
SELECT * FROM stats WHERE ip LIKE '%' OR ip LIKE '%' AND 'topic'!='' AND 'cat"!=''

But I'm still drawing some rows where both topic and cat columns are blank.

Does anyone have ideas?


Replace != with <>

You need brackets around your OR clause and no apostrophes around column names:

  (ip LIKE '%' OR ip LIKE '%')
  AND topic!='' AND cat!=''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.