When I run a "without matching" query on DailyPrice and DATAFILE_111306, I get a list of 300+ instances. I thought that the query below would give me ALL records in DATAFILE even if there were no corresponding records in DailyPrice. In fact, none of the names on the without matching query ended up on the list created from the query below. Any help with why this is happening?
SELECT DISTINCT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice
FROM DailyPrice RIGHT JOIN DATAFILE_111306 ON DailyPrice.Symbol = DATAFILE_111306.Symbol
WHERE (((DailyPrice.LocateDate) Between Now() And (Now()-8)))
ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate DESC;
4 1199 NeoPa 32,556
Recognized Expert Moderator MVP
If you do a LEFT or RIGHT JOIN (as you've done), when the data is a record with no match, the fields of the other table are all Null.
Your WHERE clause tells the query to drop ALL records where there is no match because it doesn't test for Null.
Try something like :- - SELECT DISTINCT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice
-
FROM DailyPrice RIGHT JOIN DATAFILE_111306 ON DailyPrice.Symbol = DATAFILE_111306.Symbol
-
WHERE (((DailyPrice.LocateDate) IS Null) OR ((DailyPrice.LocateDate) Between (Date()-8) And Date()))
-
ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate DESC;
Notice I changed Now() to Date() - Can you tell me why I would do that?
And I put Date()-8 first in the Between clause for clarity.
Also, bear in mind when you sort by fields that may exist only as Nulls, the unmatched records will all appear together at one end.
MMcCarthy 14,534
Recognized Expert Moderator MVP
When I run a "without matching" query on DailyPrice and DATAFILE_111306, I get a list of 300+ instances. I thought that the query below would give me ALL records in DATAFILE even if there were no corresponding records in DailyPrice. In fact, none of the names on the without matching query ended up on the list created from the query below. Any help with why this is happening?
SELECT DISTINCT DailyPrice.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice
FROM DailyPrice RIGHT JOIN DATAFILE_111306 ON DailyPrice.Symbol = DATAFILE_111306.Symbol
WHERE (((DailyPrice.LocateDate) Between Now() And (Now()-8)))
ORDER BY DailyPrice.Symbol, DailyPrice.LocateDate DESC;
You've taken all your fields from the left side DailyPrice. The query isn't returning any data from DATAFILE_111306 so there is nothing to show.
Try this:
SELECT DATAFILE_111306.Symbol, DailyPrice.LocateDate, DailyPrice.MarketPrice
FROM DailyPrice RIGHT JOIN DATAFILE_111306 ON DailyPrice.Symbol = DATAFILE_111306.Symbol
WHERE (((DailyPrice.LocateDate) Between Now() And (Now()-8)))
ORDER BY DATAFILE_111306.Symbol, DailyPrice.LocateDate DESC;
NeoPa 32,556
Recognized Expert Moderator MVP
The reason you NEVER use Now() in date checks is that Now() is a Date AND Time, whereas the fields you are checking against are just Dates.
This means if you want a date range between yesterday and today - you would actually only find items for today. This is because dates (alone) are stored as midnight of the date in question so would fall outside of the range - Between Now()-1 And Now()
Just a point - if you don't check for nulls explicitly in your WHERE clause, all non-matched records will be dropped from the query output.
Thank you both for your help. I am starting to grasp the access logic! Using the "Null" statement made sense and WORKED! Thanks again!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Irlan agous |
last post by:
Hello
i have t tables reactie and form and this query
$sql = "select reactie.persid,form.oproep,form.foto,form.id from
reactie,form
INNER JOIN reactie ON (reactie.persid = form.id) group by...
|
by: Adam Nemitoff |
last post by:
I have two tables populated during the use of an application to log
user events and application states. They are named "EventTable" and
"StateTable" and the structures follow:
EventTable:
ID...
|
by: Jack Smith |
last post by:
Hello,
I want to be able to view data from 3 tables using the JOIN statement, but
I'm not sure of how to do it. I think i don't know the syntax of the joins.I
imagine this is easy for the...
|
by: Pavel Stehule |
last post by:
Hello,
Is possible merge two arrays like
array + array => array
select array_append(array, array);
ERROR: function array_append(integer, integer) does not exist
|
by: Shahzad |
last post by:
dear respected gurus,
I would like to knew how to apply append,insert query for a self table
where no primary keys issues.
i do have problem say there are 5 rows of single record, this is data...
| |
by: Lyn |
last post by:
This one is difficult to explain, so I will cut it down to the basics.
I have a major table 'tblA' which has an autonum field 'ID-A' as primary key
(of no significance to users). 'tblA' contains...
|
by: epigram |
last post by:
I'd like to know if there is a best approach, in terms of using the Data Web
Controls (i.e. DataGrid, DataList & Repeater), for displaying data that is
the result of a query that joins two tables...
|
by: Jack |
last post by:
Hi all,
While debugging some old code from someone, I came across this stored
procedure:
SELECT dbo.TBL_COORD.COORD_ID AS ID, dbo.TBL_COORD.LATITUDE AS Latitude,
dbo.TBL_COORD.LONGITUDE AS...
|
by: No bother |
last post by:
I have a series of tables as below:
CREATE TABLE `collectorfeetable` (
`colFeeID` int(10) unsigned NOT NULL default '0',
`colFeeAmount` decimal(10,2) NOT NULL default '0.00',
`colTimeStamp`...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |