MySql Query

Hello,

Is there a more efficient way of doing below?

I need to display the name where the name has not completed a record in the ws_vp table for more than 2 days. Name only ever completes one record per date.

Thanks.
SELECT distinct(ws_vp.UID), tbl_usermanager.name from tbl_usermanager, ws_vp where ws_vp.UID not in (SELECT distinct(UID)FROM ws_vp where DATE = DATE_ADD( CURDATE( ) , INTERVAL -2 DAY ))and ws_vp.UID=tbl_usermanager.id order by DATE DESC

Open in new window

LVL 1
AUCKLANDITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris HarteThaumaturgeCommented:
You are using date_add with a minus number, shouldn't that be date_sub with a 2.

DATE_SUB( CURDATE( ) , INTERVAL 2 DAY )
0
johanntagleCommented:
Try left outer join instead of not in (hard to type code using a tablet so that's as far as I can help for now)

@munterman - it achieves the same thing, both functions are acceptable
0
FugasCommented:
Distinct operation is slow, cause it is using also ordering. I think you shouldn't have both of those tables in the first select. I thinnk you have the id in both your tables, so try something like this.

SELECT tbl_usermanager.id, tbl_usermanager.name
from tbl_usermanager
where tbl_usermanager.id not in (SELECT UID FROM ws_vp where DATE = DATE_ADD( CURDATE( ) , INTERVAL -2 DAY ))

I don't know what result you really need, so if you like more help, post your table definitions and maybe more explain your idea. Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vimal DMSenior Software EngineerCommented:
Hi,

I shall give you a logic for,

Having the "createdon" and  "updatedon" fields you can solve this issue very well.

So just write a query to minus the (updatedon-createdon) you will get the result based on the select the names
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.