SQL Search - Results not duplicated

Asked

Viewed 46 times

2

I am wanting to return a database query without repeated data. The table is called Wps_history and contains the following columns:

id
user_id
adm_user_id
type
user
lancamento
data
valor
saldo
reason
ip
inserted   

I’m doing the research as follows:

select * 
from wps_history 
where inserted between "2016-11-01 00:00:00" AND "2016-11-30 23:59:59";

Only I’m getting duplicate user data, what I need to do is filter the result by user_id.

1 answer

2

You need to use the clause DISTINCTwith the column you want the single die:

select DISTINCT(user_id) from wps_history where inserted between "2016-11-01 00:00:00" AND "2016-11-30 23:59:59"
  • Thanks, it worked perfectly. Take advantage of your help, can I check the frequency these users use my system? Example: User: user_id: 4435 Can I see using the column: date, to see how many times in the month this user enters the site? Valeu!

  • @Cicero the ideal in the new doubts that arise is for you to create another question so that other people can help you focused on your doubt

  • Thanks, I’ll do it. I didn’t create a new one because I didn’t read the rules, I was afraid of being forbidden! !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.