1

I'm fairly new to subqueries/joins but I need to run a query on a table table that was generated from another query. I know this has probably been asked before, but I have not been able to find an answer that works form me.

Basic info about my queries:

query 1:

SELECT ipAddress,userId FROM loginAttempts WHERE browser = 'IE' GROUP BY userId

query 2:

SELECT COUNT(ipAddress) AS rows,ipAddress FROM loginAttempts GROUP BY ipAddress ORDER BY ipAddress;

Mainly I need to preform a search to only show unique values that reach certain criteria then show a count of how many of each unique values are returned from that.

This is a simplified version of my queries, but the loginAttempts table tracks each login attempt from each user, and I need to see how many login attempts were made from each IP address from each user. For example...

user1, 5 attempts from x.x.x.4
user1, 2 attempts from x.x.x.5
user2, 10 attempts from x.x.x.4
user2, 2 attempts from x.x.x.6
etc...

Thank you in advance for your help!

1
  • Use both columns in group by Commented Dec 20, 2015 at 7:13

1 Answer 1

1

Try this:

Group by userid, ipAddress

SELECT COUNT(ipAddress) AS rows,ipAddress, userId 
FROM loginAttempts 
GROUP BY ipAddress, userId 
ORDER BY ipAddress

Together in group by. I hope this will help you

Sign up to request clarification or add additional context in comments.

2 Comments

@drew: thanks for editing actually I m using mobile and I dont knw is there any option like Ctrl + K?
one time I scored 201 points on my phone in one day. A nightmare. Funny thing is, I haven't done that again even on a laptop. Sorry, I don't know the short-cut.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.