Hi,
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 '%192.168.0.1%' OR ip LIKE '%192.168.1.2%' AND 'topic'!='' AND 'cat"!=''

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

Does anyone have ideas?

Cheers,

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

SELECT * FROM stats WHERE 
  (ip LIKE '%192.168.0.1%' OR ip LIKE '%192.168.1.2%')
  AND topic!='' AND cat!=''
Be a part of the DaniWeb community

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