Skip to content
Advertisement

Mysql – Finding a record that satisfies 2 exact dates

Fairly new to mysql & the stack overflow community. – I have a question that’s been bugging me.

I’m trying to return the results of individuals that have taken out a book on 2 specific dates. This is my effort so far;

I’m not sure why I’m not getting any results – When I run the query with just one date it comes up with results. I can see from these results that there are definitely records that should satisfy the criteria, I’m not sure where I’m going wrong.

Can anyone pinpoint where I’m going wrong? I thought it looked quite straightforward but it’s driving me crazy.

Thanks

Advertisement

Answer

One option uses exists twice:

With an index on loan(cardno, dateout), this should be an efficient solution.

Alternatively, you can use aggregation:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement