Displaying only records that don't have an update this month











up vote
1
down vote

favorite












MySQL and PHP



I am attempting to write a SQL statement that will allow me to identify an individual that has not checked in this month. I am stuck on how to write the code.



I have 2 tables



tbl_cust c
tbl_attend a



    SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c RIGHT OUTER JOIN tbl_attend a ON c.custRFID = a.RFID
WHERE
MONTH(a.attendDate) <> MONTH(CURDATE()) AND YEAR(a.attendDate) =
YEAR(CURDATE())


The code filters out this month, however, it returns every date prior to this month. I only want to display the names from table c that don't have an entry in table a for this month. I don't need all the records.



-------------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
1 01 02 03 E1 2018-01-03 1835 1 1
2 02 02 04 E2 2018-01-06 1235 1 1
3 01 02 03 E1 2018-02-07 1801 1 1
4 02 02 04 E2 2018-02-11 1109 1 1
5 01 02 03 E1 2018-03-03 1835 1 1
6 02 02 04 E2 2018-03-06 1235 1 1
7 01 02 03 E1 2018-04-07 1801 1 1
8 02 02 04 E2 2018-04-11 1109 1 1
9 01 02 03 E1 2018-05-01 1032 1 1


If this was May 16, 2018 the following should be the output:



-----------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
8 02 02 04 E2 2018-04-11 1109 1 1


This is only using 2 customers, as the actual table will eventually have over 5,000 customers in it. with at least 1 entry per month. Some will have 3 of 4 entries per month, however, I only want to see those with no entry in the current calendar month. I.e.... If they checked in anytime during the calendar month of May 2018, they should not be displayed on the output.



Thank you in advance.










share|improve this question
























  • Can you include the expected output as well?
    – Tim Biegeleisen
    2 days ago










  • @TimBiegeleisen ... Added more details. Thanks
    – Will D.
    2 days ago















up vote
1
down vote

favorite












MySQL and PHP



I am attempting to write a SQL statement that will allow me to identify an individual that has not checked in this month. I am stuck on how to write the code.



I have 2 tables



tbl_cust c
tbl_attend a



    SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c RIGHT OUTER JOIN tbl_attend a ON c.custRFID = a.RFID
WHERE
MONTH(a.attendDate) <> MONTH(CURDATE()) AND YEAR(a.attendDate) =
YEAR(CURDATE())


The code filters out this month, however, it returns every date prior to this month. I only want to display the names from table c that don't have an entry in table a for this month. I don't need all the records.



-------------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
1 01 02 03 E1 2018-01-03 1835 1 1
2 02 02 04 E2 2018-01-06 1235 1 1
3 01 02 03 E1 2018-02-07 1801 1 1
4 02 02 04 E2 2018-02-11 1109 1 1
5 01 02 03 E1 2018-03-03 1835 1 1
6 02 02 04 E2 2018-03-06 1235 1 1
7 01 02 03 E1 2018-04-07 1801 1 1
8 02 02 04 E2 2018-04-11 1109 1 1
9 01 02 03 E1 2018-05-01 1032 1 1


If this was May 16, 2018 the following should be the output:



-----------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
8 02 02 04 E2 2018-04-11 1109 1 1


This is only using 2 customers, as the actual table will eventually have over 5,000 customers in it. with at least 1 entry per month. Some will have 3 of 4 entries per month, however, I only want to see those with no entry in the current calendar month. I.e.... If they checked in anytime during the calendar month of May 2018, they should not be displayed on the output.



Thank you in advance.










share|improve this question
























  • Can you include the expected output as well?
    – Tim Biegeleisen
    2 days ago










  • @TimBiegeleisen ... Added more details. Thanks
    – Will D.
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











MySQL and PHP



I am attempting to write a SQL statement that will allow me to identify an individual that has not checked in this month. I am stuck on how to write the code.



I have 2 tables



tbl_cust c
tbl_attend a



    SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c RIGHT OUTER JOIN tbl_attend a ON c.custRFID = a.RFID
WHERE
MONTH(a.attendDate) <> MONTH(CURDATE()) AND YEAR(a.attendDate) =
YEAR(CURDATE())


The code filters out this month, however, it returns every date prior to this month. I only want to display the names from table c that don't have an entry in table a for this month. I don't need all the records.



-------------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
1 01 02 03 E1 2018-01-03 1835 1 1
2 02 02 04 E2 2018-01-06 1235 1 1
3 01 02 03 E1 2018-02-07 1801 1 1
4 02 02 04 E2 2018-02-11 1109 1 1
5 01 02 03 E1 2018-03-03 1835 1 1
6 02 02 04 E2 2018-03-06 1235 1 1
7 01 02 03 E1 2018-04-07 1801 1 1
8 02 02 04 E2 2018-04-11 1109 1 1
9 01 02 03 E1 2018-05-01 1032 1 1


If this was May 16, 2018 the following should be the output:



-----------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
8 02 02 04 E2 2018-04-11 1109 1 1


This is only using 2 customers, as the actual table will eventually have over 5,000 customers in it. with at least 1 entry per month. Some will have 3 of 4 entries per month, however, I only want to see those with no entry in the current calendar month. I.e.... If they checked in anytime during the calendar month of May 2018, they should not be displayed on the output.



Thank you in advance.










share|improve this question















MySQL and PHP



I am attempting to write a SQL statement that will allow me to identify an individual that has not checked in this month. I am stuck on how to write the code.



I have 2 tables



tbl_cust c
tbl_attend a



    SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c RIGHT OUTER JOIN tbl_attend a ON c.custRFID = a.RFID
WHERE
MONTH(a.attendDate) <> MONTH(CURDATE()) AND YEAR(a.attendDate) =
YEAR(CURDATE())


The code filters out this month, however, it returns every date prior to this month. I only want to display the names from table c that don't have an entry in table a for this month. I don't need all the records.



-------------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
1 01 02 03 E1 2018-01-03 1835 1 1
2 02 02 04 E2 2018-01-06 1235 1 1
3 01 02 03 E1 2018-02-07 1801 1 1
4 02 02 04 E2 2018-02-11 1109 1 1
5 01 02 03 E1 2018-03-03 1835 1 1
6 02 02 04 E2 2018-03-06 1235 1 1
7 01 02 03 E1 2018-04-07 1801 1 1
8 02 02 04 E2 2018-04-11 1109 1 1
9 01 02 03 E1 2018-05-01 1032 1 1


If this was May 16, 2018 the following should be the output:



-----------------------------------------------------------
ID RFID Date Time Status Status Code
-------------------------------------------------------------
8 02 02 04 E2 2018-04-11 1109 1 1


This is only using 2 customers, as the actual table will eventually have over 5,000 customers in it. with at least 1 entry per month. Some will have 3 of 4 entries per month, however, I only want to see those with no entry in the current calendar month. I.e.... If they checked in anytime during the calendar month of May 2018, they should not be displayed on the output.



Thank you in advance.







mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 18 at 2:08









Will D.

75




75












  • Can you include the expected output as well?
    – Tim Biegeleisen
    2 days ago










  • @TimBiegeleisen ... Added more details. Thanks
    – Will D.
    2 days ago


















  • Can you include the expected output as well?
    – Tim Biegeleisen
    2 days ago










  • @TimBiegeleisen ... Added more details. Thanks
    – Will D.
    2 days ago
















Can you include the expected output as well?
– Tim Biegeleisen
2 days ago




Can you include the expected output as well?
– Tim Biegeleisen
2 days ago












@TimBiegeleisen ... Added more details. Thanks
– Will D.
2 days ago




@TimBiegeleisen ... Added more details. Thanks
– Will D.
2 days ago












3 Answers
3






active

oldest

votes

















up vote
1
down vote













If you want someone who has ever checked in, then you can use aggregation:



select RFID
from attend a
group by RFID
having max(attendDate) < date_add(curdate(), interval 1 - day(curdate()) day);





share|improve this answer























  • Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
    – Will D.
    Nov 19 at 3:46










  • @WillD. . . . That is what this query does.
    – Gordon Linoff
    Nov 19 at 13:18










  • @Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
    – Will D.
    2 days ago










  • @WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
    – Gordon Linoff
    2 days ago










  • @Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
    – Will D.
    2 days ago


















up vote
0
down vote













I would write this as an EXISTS query:



SELECT
c.custRFID
FROM
tbl_cust c
WHERE NOT EXISTS (SELECT 1 FROM tbl_attend a
WHERE c.custRFID = a.RFID AND
MONTH(a.attendDate) = MONTH(CURDATE()) AND
YEAR(a.attendDate) = YEAR(CURDATE()));





share|improve this answer





















  • Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
    – Will D.
    Nov 19 at 3:48










  • @WillD. If mark correct is possible that would be appreciated.
    – Tim Biegeleisen
    Nov 19 at 3:51










  • Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
    – Will D.
    2 days ago










  • What is the error?
    – Tim Biegeleisen
    2 days ago










  • I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
    – Will D.
    2 days ago


















up vote
0
down vote













You can do this using LEFT JOIN.
Also, try not to use YEAR(column) & MONTH(column) functions in ON/WHERE clauses as SQL will not be able to use indeces in this case.
Something like this should do the trick:



SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c
LEFT JOIN tbl_attend a ON (
c.custRFID = a.RFID
AND a.attendDate > DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH)
AND a.attendDate <= LAST_DAY(CURDATE())
)
WHERE
a.RFID IS NULL





share|improve this answer





















  • There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
    – Will D.
    2 days ago










  • You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
    – fifonik
    2 days ago












  • Reading up on the joins... I will report back once I finish reading it.
    – Will D.
    3 hours ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357295%2fdisplaying-only-records-that-dont-have-an-update-this-month%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













If you want someone who has ever checked in, then you can use aggregation:



select RFID
from attend a
group by RFID
having max(attendDate) < date_add(curdate(), interval 1 - day(curdate()) day);





share|improve this answer























  • Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
    – Will D.
    Nov 19 at 3:46










  • @WillD. . . . That is what this query does.
    – Gordon Linoff
    Nov 19 at 13:18










  • @Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
    – Will D.
    2 days ago










  • @WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
    – Gordon Linoff
    2 days ago










  • @Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
    – Will D.
    2 days ago















up vote
1
down vote













If you want someone who has ever checked in, then you can use aggregation:



select RFID
from attend a
group by RFID
having max(attendDate) < date_add(curdate(), interval 1 - day(curdate()) day);





share|improve this answer























  • Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
    – Will D.
    Nov 19 at 3:46










  • @WillD. . . . That is what this query does.
    – Gordon Linoff
    Nov 19 at 13:18










  • @Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
    – Will D.
    2 days ago










  • @WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
    – Gordon Linoff
    2 days ago










  • @Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
    – Will D.
    2 days ago













up vote
1
down vote










up vote
1
down vote









If you want someone who has ever checked in, then you can use aggregation:



select RFID
from attend a
group by RFID
having max(attendDate) < date_add(curdate(), interval 1 - day(curdate()) day);





share|improve this answer














If you want someone who has ever checked in, then you can use aggregation:



select RFID
from attend a
group by RFID
having max(attendDate) < date_add(curdate(), interval 1 - day(curdate()) day);






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered Nov 18 at 4:20









Gordon Linoff

745k32285390




745k32285390












  • Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
    – Will D.
    Nov 19 at 3:46










  • @WillD. . . . That is what this query does.
    – Gordon Linoff
    Nov 19 at 13:18










  • @Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
    – Will D.
    2 days ago










  • @WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
    – Gordon Linoff
    2 days ago










  • @Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
    – Will D.
    2 days ago


















  • Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
    – Will D.
    Nov 19 at 3:46










  • @WillD. . . . That is what this query does.
    – Gordon Linoff
    Nov 19 at 13:18










  • @Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
    – Will D.
    2 days ago










  • @WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
    – Gordon Linoff
    2 days ago










  • @Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
    – Will D.
    2 days ago
















Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
– Will D.
Nov 19 at 3:46




Gordon, Thanks for the feedback, but we have them check in every month, and we need to be able to see only those that have not checked in this month. I will read up on the SQL manual for the group by and having to see if this will get me where I need to be.
– Will D.
Nov 19 at 3:46












@WillD. . . . That is what this query does.
– Gordon Linoff
Nov 19 at 13:18




@WillD. . . . That is what this query does.
– Gordon Linoff
Nov 19 at 13:18












@Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
– Will D.
2 days ago




@Gordan Linoff. The code works, however, it not filtering the way I intend it to work. for instance, if a record is not for today it shows them on the list. I am looking to filter results based on the current month. I tried changing day to Month and it does not work correctly.
– Will D.
2 days ago












@WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
– Gordon Linoff
2 days ago




@WillD. . . . This should only be returning RFIDs whose most recent record is before the current month, not day. That is what the date_add() is doing -- getting the first day of the month.
– Gordon Linoff
2 days ago












@Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
– Will D.
2 days ago




@Gordan Linoff ... I understand, however it is returning all 100 plus entries in the table including entries made this month.
– Will D.
2 days ago












up vote
0
down vote













I would write this as an EXISTS query:



SELECT
c.custRFID
FROM
tbl_cust c
WHERE NOT EXISTS (SELECT 1 FROM tbl_attend a
WHERE c.custRFID = a.RFID AND
MONTH(a.attendDate) = MONTH(CURDATE()) AND
YEAR(a.attendDate) = YEAR(CURDATE()));





share|improve this answer





















  • Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
    – Will D.
    Nov 19 at 3:48










  • @WillD. If mark correct is possible that would be appreciated.
    – Tim Biegeleisen
    Nov 19 at 3:51










  • Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
    – Will D.
    2 days ago










  • What is the error?
    – Tim Biegeleisen
    2 days ago










  • I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
    – Will D.
    2 days ago















up vote
0
down vote













I would write this as an EXISTS query:



SELECT
c.custRFID
FROM
tbl_cust c
WHERE NOT EXISTS (SELECT 1 FROM tbl_attend a
WHERE c.custRFID = a.RFID AND
MONTH(a.attendDate) = MONTH(CURDATE()) AND
YEAR(a.attendDate) = YEAR(CURDATE()));





share|improve this answer





















  • Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
    – Will D.
    Nov 19 at 3:48










  • @WillD. If mark correct is possible that would be appreciated.
    – Tim Biegeleisen
    Nov 19 at 3:51










  • Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
    – Will D.
    2 days ago










  • What is the error?
    – Tim Biegeleisen
    2 days ago










  • I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
    – Will D.
    2 days ago













up vote
0
down vote










up vote
0
down vote









I would write this as an EXISTS query:



SELECT
c.custRFID
FROM
tbl_cust c
WHERE NOT EXISTS (SELECT 1 FROM tbl_attend a
WHERE c.custRFID = a.RFID AND
MONTH(a.attendDate) = MONTH(CURDATE()) AND
YEAR(a.attendDate) = YEAR(CURDATE()));





share|improve this answer












I would write this as an EXISTS query:



SELECT
c.custRFID
FROM
tbl_cust c
WHERE NOT EXISTS (SELECT 1 FROM tbl_attend a
WHERE c.custRFID = a.RFID AND
MONTH(a.attendDate) = MONTH(CURDATE()) AND
YEAR(a.attendDate) = YEAR(CURDATE()));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 2:27









Tim Biegeleisen

209k1380129




209k1380129












  • Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
    – Will D.
    Nov 19 at 3:48










  • @WillD. If mark correct is possible that would be appreciated.
    – Tim Biegeleisen
    Nov 19 at 3:51










  • Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
    – Will D.
    2 days ago










  • What is the error?
    – Tim Biegeleisen
    2 days ago










  • I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
    – Will D.
    2 days ago


















  • Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
    – Will D.
    Nov 19 at 3:48










  • @WillD. If mark correct is possible that would be appreciated.
    – Tim Biegeleisen
    Nov 19 at 3:51










  • Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
    – Will D.
    2 days ago










  • What is the error?
    – Tim Biegeleisen
    2 days ago










  • I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
    – Will D.
    2 days ago
















Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
– Will D.
Nov 19 at 3:48




Tim, thanks for the feedback, I will check the manual to read up on the EXISTS query options. I will keep you informed on my progress is this works for me.
– Will D.
Nov 19 at 3:48












@WillD. If mark correct is possible that would be appreciated.
– Tim Biegeleisen
Nov 19 at 3:51




@WillD. If mark correct is possible that would be appreciated.
– Tim Biegeleisen
Nov 19 at 3:51












Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
– Will D.
2 days ago




Tim, This gives me an error when I attempt to run the sql... I will keep checking my code.
– Will D.
2 days ago












What is the error?
– Tim Biegeleisen
2 days ago




What is the error?
– Tim Biegeleisen
2 days ago












I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
– Will D.
2 days ago




I got this past the error, but it returns all 176 records in the table. not sure this is going to work for what I need. If a customer has been a member for 12 months then they will have 12 entries. I only want to see the most current entry ONLY if it was not from this calendar month, i.e. November 1-20 of 2018. I don't want to see every entry of those in past. The goal here is so we can easliy identify who we need to call this month.
– Will D.
2 days ago










up vote
0
down vote













You can do this using LEFT JOIN.
Also, try not to use YEAR(column) & MONTH(column) functions in ON/WHERE clauses as SQL will not be able to use indeces in this case.
Something like this should do the trick:



SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c
LEFT JOIN tbl_attend a ON (
c.custRFID = a.RFID
AND a.attendDate > DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH)
AND a.attendDate <= LAST_DAY(CURDATE())
)
WHERE
a.RFID IS NULL





share|improve this answer





















  • There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
    – Will D.
    2 days ago










  • You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
    – fifonik
    2 days ago












  • Reading up on the joins... I will report back once I finish reading it.
    – Will D.
    3 hours ago















up vote
0
down vote













You can do this using LEFT JOIN.
Also, try not to use YEAR(column) & MONTH(column) functions in ON/WHERE clauses as SQL will not be able to use indeces in this case.
Something like this should do the trick:



SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c
LEFT JOIN tbl_attend a ON (
c.custRFID = a.RFID
AND a.attendDate > DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH)
AND a.attendDate <= LAST_DAY(CURDATE())
)
WHERE
a.RFID IS NULL





share|improve this answer





















  • There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
    – Will D.
    2 days ago










  • You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
    – fifonik
    2 days ago












  • Reading up on the joins... I will report back once I finish reading it.
    – Will D.
    3 hours ago













up vote
0
down vote










up vote
0
down vote









You can do this using LEFT JOIN.
Also, try not to use YEAR(column) & MONTH(column) functions in ON/WHERE clauses as SQL will not be able to use indeces in this case.
Something like this should do the trick:



SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c
LEFT JOIN tbl_attend a ON (
c.custRFID = a.RFID
AND a.attendDate > DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH)
AND a.attendDate <= LAST_DAY(CURDATE())
)
WHERE
a.RFID IS NULL





share|improve this answer












You can do this using LEFT JOIN.
Also, try not to use YEAR(column) & MONTH(column) functions in ON/WHERE clauses as SQL will not be able to use indeces in this case.
Something like this should do the trick:



SELECT
c.custRFID,
a.attendID,
a.RFID,
a.attendDate,
a.attendStatus,
a.attendStatusCode,
a.attendNotes
FROM
tbl_cust c
LEFT JOIN tbl_attend a ON (
c.custRFID = a.RFID
AND a.attendDate > DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH)
AND a.attendDate <= LAST_DAY(CURDATE())
)
WHERE
a.RFID IS NULL






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









fifonik

974




974












  • There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
    – Will D.
    2 days ago










  • You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
    – fifonik
    2 days ago












  • Reading up on the joins... I will report back once I finish reading it.
    – Will D.
    3 hours ago


















  • There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
    – Will D.
    2 days ago










  • You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
    – fifonik
    2 days ago












  • Reading up on the joins... I will report back once I finish reading it.
    – Will D.
    3 hours ago
















There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
– Will D.
2 days ago




There will never be a Null entry in the RFID Column of any of the tables. If the RFID tag is not scanned the record does not exist.
– Will D.
2 days ago












You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
– fifonik
2 days ago






You should read about left join a bit more: dev.mysql.com/doc/refman/5.7/en/join.html "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find rows in a table that have no counterpart in another table: "
– fifonik
2 days ago














Reading up on the joins... I will report back once I finish reading it.
– Will D.
3 hours ago




Reading up on the joins... I will report back once I finish reading it.
– Will D.
3 hours ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357295%2fdisplaying-only-records-that-dont-have-an-update-this-month%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga