So you have a table, and one of its attributes is an IP address. What are the other attributes that you can use to find any particular record? Is this a server application, and you're trying to find the record for the client IP? You really haven't provided enough information to help you.
But SQL runs on the database server. So your only choice (if you want to run this on the database server) would be to use whatever admin session auditing views/procedures your particular database gives you.
Which database are you using? What is forcing you to use SQL?