473,626 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql select max note for a row and join

Shashi Sadasivan
1,435 Recognized Expert Top Contributor
hi,
i have an issue with joining some table.
i have 3 tables.
product - (productID, total)
items - (productID, itemNo, total)
note - (noteID, productID, note)

each product has one or more items
each product has zero or more notes to it to the note

i need to show each product along with the last note put on it (there might be zero or more notes per product)

what i want to select is productID,total ,item_no,note
the note should be the latest note for that productID
managed to get those rows which dont have a note. but cant work the other way around!

Thanks
-shashi
Aug 23 '07 #1
3 2479
ak1dnar
1,584 Recognized Expert Top Contributor
hi,
i have an issue with joining some table.
i have 3 tables.
product - (productID, total)
items - (productID, itemNo, total)
note - (noteID, productID, note)

each product has one or more items
each product has zero or more notes to it to the note

i need to show each product along with the last note put on it (there might be zero or more notes per product)

what i want to select is productID,total ,item_no,note
the note should be the latest note for that productID
managed to get those rows which dont have a note. but cant work the other way around!

Thanks
-shashi


Hi Shashi,

When you joining note table with others two table you can Select the Maximum noteid for the specific product.

Do you think this is the one you looking for. Post back if not.

Expand|Select|Wrap|Line Numbers
  1. select items.productID,items.total,items.itemno,note.note from note
  2. Left join items on items.productID=note.productID 
  3. where note.productid=1001 and note.noteid=(select max(noteid) from note where note.productid=1001)
Aug 23 '07 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi Shashi,

When you joining note table with others two table you can Select the Maximum noteid for the specific product.

Do you think this is the one you looking for. Post back if not.

Expand|Select|Wrap|Line Numbers
  1. select items.productID,items.total,items.itemno,note.note from note
  2. Left join items on items.productID=note.productID 
  3. where note.productid=1001 and note.noteid=(select max(noteid) from note where note.productid=1001)
Not really....
1. i have to list it for all products.
2. if there is no note for that product the product should still be shown
in the above case, i would need to programatically run this query for each product
and if there is a product without any note, it would not be shown
thanks
Aug 23 '07 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi Shashi,

When you joining note table with others two table you can Select the Maximum noteid for the specific product.

Do you think this is the one you looking for. Post back if not.

Expand|Select|Wrap|Line Numbers
  1. select items.productID,items.total,items.itemno,note.note from note
  2. Left join items on items.productID=note.productID 
  3. where note.productid=1001 and note.noteid=(select max(noteid) from note where note.productid=1001)
Sorry about the last reply...
I did not realize about the left join and took it for granted.
Yes it does work great now....thanks mate
Aug 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1371
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | TicketNo | evaluation | Username ------------------------------------------------------------------------------- 1 1 9 Jamie 2 1 8.5 ...
0
1377
by: Denis St-Michel | last post by:
Hello all. Here are my Tables Tickets ------- id Notes -----
3
3540
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
5
11499
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold { CarsSoldID int (primary key) MonthID int DealershipID int NumberCarsSold int
4
2843
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
17
5004
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
3
6447
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
1
4167
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
0
1908
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry with the desired join key in the 'many-only' table." ... happens when I click on an entry of a combobox. HELP!! Here's the background:
6
4838
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8504
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2625
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 we have to send another system

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.