Sql help please.

Results 1 to 2 of 2

Thread: Sql help please.

  1. #1
    Join Date
    Dec 1969

    Default Sql help please.

    Hello good people.<BR>Here is my problem (simplified)<BR>I have 2 tables:<BR>Company_Update and Company (with Comp_id being a link between two). 1 Company can have many updates. Now, I need to populate a column called "DateOfLastUpdate" in the Company table with the date of the latest update in the Company_Update Table. I know I need to use MAX function but I keep getting error about using aggregate function in my Update.<BR>Here is what I tried:<BR><BR>update Company<BR> set dtLastUpdates = cu.dtAnnounced<BR> from Company c<BR> join CompanyUpdate cu on c.CompanyID=cu.CompanyID<BR> WHERE cu.dtAnnounced = (select max(cu.dtAnnounced) from CompanyUpdate)<BR><BR>The error I get is "Aggregate may not appear in the WHERE clause".<BR><BR>Please teach me how to accomplish what I&#039;m trying.<BR>Thank you all in advance.<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Sql help please.

    <BR>update Company<BR>    set dtLastUpdates = (select max(dtAnnounced)<BR>    from CompanyUpdate cu where c.CompanyID=cu.CompanyID)<BR>    WHERE companyId in (select companyId from CompanyUpdate) <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts