473,405 Members | 2,185 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,405 software developers and data experts.

output the latest date for each foreign key

I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO
I try to get the output of the most latest date for each ItemLookUpID
and
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)
index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 4 4/2/2006 1500
2 4 4/8/2006 2000
3 3 4/1/2006 50
4 3 5/7/2006 80
5 2 8/4/2006 67
6 2 9/4/2006 55
7 2 9/6/2006 500

I wrote the sql stmt as below, but it only fetched as below (the most
latest date among all records which is wrong).
index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 4 5/7/2006 80
select i.*, h.dtbegin, h.price
from ItemLookUp i RIGHT OUTER JOIN ItemSTDPriceHistory h
ON i.index_id = h.ItemLookUpID
where h.dtbegin = (select max(h.dtbegin) from ItemSTDPriceHistory
h)
order by i.itemnsn, i.itemdescription, i.itemunit, h.dtbegin, h.price
asc
so the correct output will be as below (the latest date with each
itemlookupID) and please help with my sql stmt to output the records
as below

index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 2 9/6/2006 500
2 3 5/7/2006 80
3 4 4/8/2006 2000

Jun 14 '06 #1
8 2163
the reply status shows 1 new of 2
i think someone replied for my posting, but cannot see it.
what happened?

TGEAR wrote:
I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO
I try to get the output of the most latest date for each ItemLookUpID
and
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)
index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 4 4/2/2006 1500
2 4 4/8/2006 2000
3 3 4/1/2006 50
4 3 5/7/2006 80
5 2 8/4/2006 67
6 2 9/4/2006 55
7 2 9/6/2006 500

I wrote the sql stmt as below, but it only fetched as below (the most
latest date among all records which is wrong).
index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 4 5/7/2006 80
select i.*, h.dtbegin, h.price
from ItemLookUp i RIGHT OUTER JOIN ItemSTDPriceHistory h
ON i.index_id = h.ItemLookUpID
where h.dtbegin = (select max(h.dtbegin) from ItemSTDPriceHistory
h)
order by i.itemnsn, i.itemdescription, i.itemunit, h.dtbegin, h.price
asc
so the correct output will be as below (the latest date with each
itemlookupID) and please help with my sql stmt to output the records
as below

index_id ItemLookupID dtbegin price
---------------------------------------------------------------------------*----------------

1 2 9/6/2006 500
2 3 5/7/2006 80
3 4 4/8/2006 2000


Jun 14 '06 #2
TGEAR (te******@hotmail.com) writes:
I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO
This table does not have a primary key? Furthermore what purpose does
index_id serve? I would expect (ItemLookupID, dtbegin) to be unique.
I try to get the output of the most latest date for each ItemLookUpID
SELECT a.ItemLookUpID, a.dtbegin, a.price
FROM ItemSTDPriceHistory a
JOIN (SELECT ItemLookUpID, maxdate = MAX(dtbegin)
FROM ItemSTDPriceHistory
GROUP BY ItemLookUpID) AS b
ON a.ItemLookUpID = b.ItemLookUpID
AND a.dtbegin = b.maxdate
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)


You seem to know how to write SELECT statement. Then you should know
how to write INSERT statements as well. It's simple anyway. First you
say:

INSERT tbl(col1, col2, col3, ...)

(columns that are nullable or have default values can be left out. IDENTITY
and timestamp columns must be left out.)

The INSERT clause is followed either by a SELECT statement, or a VALUES
clause if you only want to insert a row from constants or variables:

VALUES (val1, val2, val3, ...)

The values can be expressions, but cannot include queries.

That's the basics. Now you can practice. :-) When in doubt consult Books
Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 14 '06 #3
Thank you for your help.
here index_id is a primary key and the combo of ItemLookupID and
dtbegin is unique.

"ItemSTDPriceHistory table" is a child table of "ItemLookUp table"
The itemlookupID in the ItemSTDPriceHistory table is the foreign key of
the ItemLookUp table (Parent table).

I also need to list all values from the parent table as well even
though there is no record existed in the ItemSTDPriceHistory table
(child table)
..
When I run your kind query, if there is no value in the child table, no
output is appeared.
I tried to show the output from the parent table even though there is
no data in the child table and so I used RIGHT OUTER JOIN in my sql
stmt.

I changed your INNER JOIN to RIGHT OUTER JOIN, but nothing was
appeared.
Can you help me on this issue again? thanks in advance.

btw, your step by step instruction of INSERT statement is very helpful.

Erland Sommarskog wrote:
TGEAR (te******@hotmail.com) writes:
I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO


This table does not have a primary key? Furthermore what purpose does
index_id serve? I would expect (ItemLookupID, dtbegin) to be unique.
I try to get the output of the most latest date for each ItemLookUpID


SELECT a.ItemLookUpID, a.dtbegin, a.price
FROM ItemSTDPriceHistory a
JOIN (SELECT ItemLookUpID, maxdate = MAX(dtbegin)
FROM ItemSTDPriceHistory
GROUP BY ItemLookUpID) AS b
ON a.ItemLookUpID = b.ItemLookUpID
AND a.dtbegin = b.maxdate
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)


You seem to know how to write SELECT statement. Then you should know
how to write INSERT statements as well. It's simple anyway. First you
say:

INSERT tbl(col1, col2, col3, ...)

(columns that are nullable or have default values can be left out. IDENTITY
and timestamp columns must be left out.)

The INSERT clause is followed either by a SELECT statement, or a VALUES
clause if you only want to insert a row from constants or variables:

VALUES (val1, val2, val3, ...)

The values can be expressions, but cannot include queries.

That's the basics. Now you can practice. :-) When in doubt consult Books
Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Jun 14 '06 #4
I think I should state more clearly. Sorry for the mess.

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i LEFT OUTER JOIN
ItemSTDPriceHistory h ON i.index_id =
h.ItemLookUpID
WHERE (h.dtbegin =
(SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory))
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC

ItemLookUp table is a parent table of ItemSTDPriceHistory table.
ItemLookUp.index_id is the primary key.
Relationship b/w two table is one-to-many:
ItemLookUp.index_id = ItemSTDPriceHistory.ItemLookUpID

I used OUTER JOIN there since I need to get the parent records even
though if there is no data in the child table.
Also, If i run that sql stmt, i only get one data, but I need to get
the latest date for each foreign key.

so here is the sample data

h.index_id h.ItemLookupID h.dtbegin h.price
i.itmnumber i.descript
---------------------------------------------------------------------------**---------------------------------------------------

1 4 4/2/2006 1500 000001
paper
2 4 4/8/2006 2000 000002
eraser
3 3 4/1/2006 50 000001
pencil
4 3 5/7/2006 80 000002
ballpen
5 2 8/4/2006 67 000001
keyboard
6 2 9/4/2006 55 000002
mornitor
7 2 9/6/2006 500 000003
calendar

And Expected output:

h.index_id h.ItemLookupID h.dtbegin h.price
i.itmnumber i.descript
---------------------------------------------------------------------------**------------------------------------------------
1 2 9/6/2006 500
000003 calendar
2 3 5/7/2006 80
000002 ballpen
3 4 4/8/2006 2000
000002 eraser

TGEAR wrote:
Thank you for your help.
here index_id is a primary key and the combo of ItemLookupID and
dtbegin is unique.

"ItemSTDPriceHistory table" is a child table of "ItemLookUp table"
The itemlookupID in the ItemSTDPriceHistory table is the foreign key of
the ItemLookUp table (Parent table).

I also need to list all values from the parent table as well even
though there is no record existed in the ItemSTDPriceHistory table
(child table)
.
When I run your kind query, if there is no value in the child table, no
output is appeared.
I tried to show the output from the parent table even though there is
no data in the child table and so I used RIGHT OUTER JOIN in my sql
stmt.

I changed your INNER JOIN to RIGHT OUTER JOIN, but nothing was
appeared.
Can you help me on this issue again? thanks in advance.

btw, your step by step instruction of INSERT statement is very helpful.

Erland Sommarskog wrote:
TGEAR (te******@hotmail.com) writes:
I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO


This table does not have a primary key? Furthermore what purpose does
index_id serve? I would expect (ItemLookupID, dtbegin) to be unique.
I try to get the output of the most latest date for each ItemLookUpID


SELECT a.ItemLookUpID, a.dtbegin, a.price
FROM ItemSTDPriceHistory a
JOIN (SELECT ItemLookUpID, maxdate = MAX(dtbegin)
FROM ItemSTDPriceHistory
GROUP BY ItemLookUpID) AS b
ON a.ItemLookUpID = b.ItemLookUpID
AND a.dtbegin = b.maxdate
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)


You seem to know how to write SELECT statement. Then you should know
how to write INSERT statements as well. It's simple anyway. First you
say:

INSERT tbl(col1, col2, col3, ...)

(columns that are nullable or have default values can be left out. IDENTITY
and timestamp columns must be left out.)

The INSERT clause is followed either by a SELECT statement, or a VALUES
clause if you only want to insert a row from constants or variables:

VALUES (val1, val2, val3, ...)

The values can be expressions, but cannot include queries.

That's the basics. Now you can practice. :-) When in doubt consult Books
Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Jun 14 '06 #5
Please help me on this issue. thanks

TGEAR wrote:
I think I should state more clearly. Sorry for the mess.

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i LEFT OUTER JOIN
ItemSTDPriceHistory h ON i.index_id =
h.ItemLookUpID
WHERE (h.dtbegin =
(SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory))
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC

ItemLookUp table is a parent table of ItemSTDPriceHistory table.
ItemLookUp.index_id is the primary key.
Relationship b/w two table is one-to-many:
ItemLookUp.index_id = ItemSTDPriceHistory.ItemLookUpID

I used OUTER JOIN there since I need to get the parent records even
though if there is no data in the child table.
Also, If i run that sql stmt, i only get one data, but I need to get
the latest date for each foreign key.

so here is the sample data

h.index_id h.ItemLookupID h.dtbegin h.price
i.itmnumber i.descript
---------------------------------------------------------------------------**---------------------------------------------------

1 4 4/2/2006 1500 000001
paper
2 4 4/8/2006 2000 000002
eraser
3 3 4/1/2006 50 000001
pencil
4 3 5/7/2006 80 000002
ballpen
5 2 8/4/2006 67 000001
keyboard
6 2 9/4/2006 55 000002
mornitor
7 2 9/6/2006 500 000003
calendar

And Expected output:

h.index_id h.ItemLookupID h.dtbegin h.price
i.itmnumber i.descript
---------------------------------------------------------------------------**------------------------------------------------
1 2 9/6/2006 500
000003 calendar
2 3 5/7/2006 80
000002 ballpen
3 4 4/8/2006 2000
000002 eraser

TGEAR wrote:
Thank you for your help.
here index_id is a primary key and the combo of ItemLookupID and
dtbegin is unique.

"ItemSTDPriceHistory table" is a child table of "ItemLookUp table"
The itemlookupID in the ItemSTDPriceHistory table is the foreign key of
the ItemLookUp table (Parent table).

I also need to list all values from the parent table as well even
though there is no record existed in the ItemSTDPriceHistory table
(child table)
.
When I run your kind query, if there is no value in the child table, no
output is appeared.
I tried to show the output from the parent table even though there is
no data in the child table and so I used RIGHT OUTER JOIN in my sql
stmt.

I changed your INNER JOIN to RIGHT OUTER JOIN, but nothing was
appeared.
Can you help me on this issue again? thanks in advance.

btw, your step by step instruction of INSERT statement is very helpful.

Erland Sommarskog wrote:
TGEAR (te******@hotmail.com) writes:
> I have an ItemSTDPriceHistory table as below and this is a child table
> of itemlookup table with one to many relationship.
>
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
> drop table [dbo].[ItemSTDPriceHistory]
> GO
>
>
> CREATE TABLE [dbo].[ItemSTDPriceHistory] (
> [index_id] [int] NOT NULL ,
> [ItemLookUpID] [int] NOT NULL ,
> [dtbegin] [datetime] NOT NULL ,
> [price] [decimal](18, 0) NOT NULL ,
> ) ON [PRIMARY]
> GO

This table does not have a primary key? Furthermore what purpose does
index_id serve? I would expect (ItemLookupID, dtbegin) to be unique.

> I try to get the output of the most latest date for each ItemLookUpID

SELECT a.ItemLookUpID, a.dtbegin, a.price
FROM ItemSTDPriceHistory a
JOIN (SELECT ItemLookUpID, maxdate = MAX(dtbegin)
FROM ItemSTDPriceHistory
GROUP BY ItemLookUpID) AS b
ON a.ItemLookUpID = b.ItemLookUpID
AND a.dtbegin = b.maxdate

> these are sample records. (I am sorry I do not know how to write a sql
> statment with records in it)

You seem to know how to write SELECT statement. Then you should know
how to write INSERT statements as well. It's simple anyway. First you
say:

INSERT tbl(col1, col2, col3, ...)

(columns that are nullable or have default values can be left out. IDENTITY
and timestamp columns must be left out.)

The INSERT clause is followed either by a SELECT statement, or a VALUES
clause if you only want to insert a row from constants or variables:

VALUES (val1, val2, val3, ...)

The values can be expressions, but cannot include queries.

That's the basics. Now you can practice. :-) When in doubt consult Books
Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ds/books..mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Jun 15 '06 #6
think I should state more clearly. Sorry for the mess.

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i LEFT OUTER JOIN
ItemSTDPriceHistory h ON i.index_id =
h.ItemLookUpID
WHERE (h.dtbegin =
(SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory))
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC
ItemLookUp table is a parent table of ItemSTDPriceHistory table.
ItemLookUp.index_id is the primary key.
Relationship b/w two table is one-to-many:
ItemLookUp.index_id = ItemSTDPriceHistory.ItemLookUpID
I used OUTER JOIN there since I need to get the parent records even
though if there is no data in the child table.
Also, If i run that sql stmt, i only get one data, but I need to get
the latest date for each foreign key.
Erland Sommarskog wrote:
TGEAR (te******@hotmail.com) writes:
I have an ItemSTDPriceHistory table as below and this is a child table
of itemlookup table with one to many relationship.

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[ItemSTDPriceHistory]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[ItemSTDPriceHistory]
GO
CREATE TABLE [dbo].[ItemSTDPriceHistory] (
[index_id] [int] NOT NULL ,
[ItemLookUpID] [int] NOT NULL ,
[dtbegin] [datetime] NOT NULL ,
[price] [decimal](18, 0) NOT NULL ,
) ON [PRIMARY]
GO


This table does not have a primary key? Furthermore what purpose does
index_id serve? I would expect (ItemLookupID, dtbegin) to be unique.
I try to get the output of the most latest date for each ItemLookUpID


SELECT a.ItemLookUpID, a.dtbegin, a.price
FROM ItemSTDPriceHistory a
JOIN (SELECT ItemLookUpID, maxdate = MAX(dtbegin)
FROM ItemSTDPriceHistory
GROUP BY ItemLookUpID) AS b
ON a.ItemLookUpID = b.ItemLookUpID
AND a.dtbegin = b.maxdate
these are sample records. (I am sorry I do not know how to write a sql
statment with records in it)


You seem to know how to write SELECT statement. Then you should know
how to write INSERT statements as well. It's simple anyway. First you
say:

INSERT tbl(col1, col2, col3, ...)

(columns that are nullable or have default values can be left out. IDENTITY
and timestamp columns must be left out.)

The INSERT clause is followed either by a SELECT statement, or a VALUES
clause if you only want to insert a row from constants or variables:

VALUES (val1, val2, val3, ...)

The values can be expressions, but cannot include queries.

That's the basics. Now you can practice. :-) When in doubt consult Books
Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Jun 15 '06 #7
On 14 Jun 2006 16:19:29 -0700, TGEAR wrote:
I think I should state more clearly. Sorry for the mess.

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i LEFT OUTER JOIN
ItemSTDPriceHistory h ON i.index_id =
h.ItemLookUpID
WHERE (h.dtbegin =
(SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory))
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC


Hi TGEAR,

The WHERE clause effectively turns the outer join back into an inner
join. Remember that rows retained by the outer join get a bunch of NULLs
for the columns in the other table (the one alised as h in your query).
So any WHERE cllause that involves those column will automatically
remove them again, since a comparison against NULL can never evaluate to
true. You can fix this problem by moving the dtbegin test from the WHERE
clause to the ON clause.

Also, you need to correlate the subquery against the main query. As yoou
have written the query, only ItemSTDPriceHistory with a date of 9/6/2006
(BTW, is that June 9th or September 6th?) will be selected, since that
is the MAX(dtbegin) in that table.

Try this query instead:

SELECT i.*, -- NEVER USE SELECT * IN PRODUCTION CODE !!!!!!
h.dtbegin, h.price
FROM ItemLookUp i
LEFT JOIN ItemSTDPriceHistory h
ON i.index_id = h.ItemLookUpID
AND h.dtbegin = (SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory AS h2
WHERE h2.ItemLookUpID = i.index_id)
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC

(Untested - see www.aspfaq.com/5006 if you prefer a tested reply)

--
Hugo Kornelis, SQL Server MVP
Jun 15 '06 #8
TGEAR (te******@hotmail.com) writes:
I think I should state more clearly. Sorry for the mess.

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i LEFT OUTER JOIN
ItemSTDPriceHistory h ON i.index_id =
h.ItemLookUpID
WHERE (h.dtbegin =
(SELECT MAX(dtbegin)
FROM ItemSTDPriceHistory))
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC
This should probably be

SELECT i.*, h.dtbegin, h.price
FROM ItemLookUp i
LEFT JOIN ItemSTDPriceHistory h
ON i.index_id = h.ItemLookUpID
AND h.dtbegin = (SELECT MAX(h2.dtbegin)
FROM ItemSTDPriceHistory h2
WHERE h2.ItemLookUpID = h.ItemLookupID
ORDER BY i.itmnumber, i.descript, h.dtbegin, h.price DESC

1) You must correlate the subquery with the outer instance of
ItemStdPriceHistory.

2) If you have a LEFT JOIN, and then have a WHERE condition which includes
the right-hand side of the table, you have effectively made the outer
join an inner join, as you filter all rows where the columns evaluates
to NULL on the right. (FROM - JOIN are evaluated before WHERE.)
so here is the sample data

h.index_id h.ItemLookupID h.dtbegin h.price
i.itmnumber i.descript
-------------------------------------------------------------------------- -**---------------------------------------------------
1 4 4/2/2006 1500 000001


Since you did not take the occassion to practice INSERT statements, the
query above is not tested.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 15 '06 #9

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

Similar topics

5
by: Marcel Akkerman | last post by:
Hi, Does anyone have a clue how to reduce the number of nodes using XSLT? When outputing all nodes in order I could just use <xsl:for-each select="name"> But what if I, besides sorting and...
2
by: John Baker | last post by:
Hi: I have used this group a number of times simply because while the manuals for Access may show the technology, but most are really weak on how to apply it in special situations and the...
7
by: Scott Frankel | last post by:
Still too new to SQL to have run across this yet ... How does one return the latest row from a table, given multiple entries of varying data? i.e.: given a table that looks like this: color...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
4
by: hph | last post by:
Okay, another trivial matter that I can't solve. I have a variable - $lastdate - that is the latest date any record in a MySQL database was updated. Its MySQL format is TIMESTAMP. If I say I...
0
by: TGEAR | last post by:
I have an ItemSTDPriceHistory table as below and this is a child table of itemlookup table with one to many relationship. if exists (select * from dbo.sysobjects where id = object_id(N'.') and...
4
by: TGEAR | last post by:
Itemlookup table Field names : index_id (primary key), itemno, description. It has a child table, which is ItemPriceHistory table The relationship to the child table is one (parent table)-to-many...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
2
by: Coxmg | last post by:
I have several related tables. One table lists orders with due dates for SKUs while another table lists components of a SKU (diamonds). A third related table lists diamond IDs and diamond inventory....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.