473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query that returns record that arn't duplicated in another table

Hi.

I have a table (websitehits) which holds statistics about websites.
This table has a date field (datecounted). What I need is to create a
query which returns a list of dates between two date ranges (say a
year ago from today and a year from now) which only shows dates that
haven't been used in the websitehits table for a given website.

For example if my table contains something like:

Website Datecounted Hits
Site1 01/01/04 6000
Site1 01/02/04 6500
Site1 01/03/04 6250
Site2 01/03/04 1000
Site2 01/04/04 1200
Site2 01/05/04 1500

So if query for ‘site1' then I'd get a list of all dates between
30/11/03 to 30/11/05 with the exception of the dates 01/01/04,
01/02/04 and 01/03/04.

So far I've tried to do this using another table named calendar which
contains a very long list of dates and to use this to produce the list
– but I'm not getting very far.

By the way I'm using sql server, an I need this query to generate a
list for an asp page - so I need to pass the website name as a
parameter so I guess I need to make this query as a stored procedure.

Does anyone know how this can be done?
Jul 20 '05 #1
1 1358
On 30 Nov 2004 03:18:02 -0800, Lukelrc wrote:
Hi.

I have a table (websitehits) which holds statistics about websites.
This table has a date field (datecounted). What I need is to create a
query which returns a list of dates between two date ranges (say a
year ago from today and a year from now) which only shows dates that
haven't been used in the websitehits table for a given website.

For example if my table contains something like:

Website Datecounted Hits
Site1 01/01/04 6000
Site1 01/02/04 6500
Site1 01/03/04 6250
Site2 01/03/04 1000
Site2 01/04/04 1200
Site2 01/05/04 1500

So if query for ‘site1' then I'd get a list of all dates between
30/11/03 to 30/11/05 with the exception of the dates 01/01/04,
01/02/04 and 01/03/04.

So far I've tried to do this using another table named calendar which
contains a very long list of dates and to use this to produce the list
– but I'm not getting very far.

By the way I'm using sql server, an I need this query to generate a
list for an asp page - so I need to pass the website name as a
parameter so I guess I need to make this query as a stored procedure.

Does anyone know how this can be done?


Hi Lukelrc,

Two possibilities (both untested, so beware of typos)

SELECT Calendar.dt
FROM Calendar
WHERE NOT EXISTS
(SELECT *
FROM websitehits
WHERE websitehits.Website = @Website
AND websitehits.Datecounted = Calendar.dt)

SELECT Calendar.dt
FROM Calendar
LEFT JOIN websitehits
ON websitehits.Website = @Website
AND websitehits.Datecounted = Calendar.dt
WHERE websitehits.dt IS NULL

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ralph Freshour | last post by:
I'm not sure the follow multiple table query is the right way to do what I need to do although it seems to be working: $php_SQL = "SELECT * ". "FROM basics, personal, photos ". "WHERE...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
6
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
1
by: commodityintelligence | last post by:
Greetings, I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming...
6
by: Phil Stanton | last post by:
I am running a query that calls a function used to format addresses depending on the width of a control on a report that shows that address. The same query is used as the RecordSource of lots of...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
7
by: Wildster | last post by:
Hi, I’ve setup a table which contains records with multiple duplicated time fields (tblTime_Slots) i.e. ID Time_Slot 1 08:00 2 08:00 3 09:00 4 09:00 etc…
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.