Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9044033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:53:08+00:00 2026-06-16T10:53:08+00:00

In the table ogitems, I have a column called itemname, month, and price. There

  • 0

In the table “ogitems”, I have a column called “itemname”, “month”, and “price”.

There duplicate items, arranged by month.

I want to check “itemname” to see if any rows have the same value for itemname, and if yes, echo the “itemname” along with the last two months and the pricing for these two months.

EXAMPLE:

“itemname” = CHEESE CHEDDAR

CHEESE CHEDDAR is found in months 11 AND 12 (so there is two records/rows for CHEESE CHEDDAR). 11 has “price” of 51 while 12 has “price” of 54

I want to echo that information into an anchor tag…

<a href="pricetrend.php?date=<?php echo "" . $row['month'] . "" ?>&price1=<?php echo $price1; ?>&price2=<?php echo $price2; ?>&item=<?php echo "" . $row['itemname'] . ""?>;">

Basically, I am trying to grab the two most recent prices for one item and echo them into this anchor tag. Thanks in advance for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:53:09+00:00Added an answer on June 16, 2026 at 10:53 am

    I am assuming that your month is a date field, this should work

    SQL Fiddle link: http://sqlfiddle.com/#!2/d63a0/4

    SELECT * FROM (
                     SELECT
                            o.itemname,
                            o.month,
                            ( SELECT price FROM ogitems i WHERE i.itemname = o.itemname AND i.month<o.month ORDER BY MONTH DESC LIMIT 1) AS last_month_price,
                            o.price AS current_month_price
                    FROM
                        ogitems o
                    ORDER BY
                        o.month DESC
    
                  ) AS items
    GROUP BY
      items.itemname
    HAVING
      items.last_month_price IS NOT NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table A has two columns: ID and name I want to input 3 ID
Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get
Table: items Create Table: CREATE TABLE `items` ( `ite_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
Table DEPARTMEnT TABLE EMPLOYEE There is the Operations Department which has not any employee.
Table - user_feed column name - date_n_time (type - datetime) How do I write
I have the following sql tables oitems table +---------+-----------+----------+ | orderid | catalogid |
Table Category (c) has a 1:many relationship with Table Question: a Category can have
Table one: products Which have fields like products_id products_price master_categories_id Table two: specials .
Table 1 - users id username items 1 Paul 1(0020);2(0001); Table 2 - items
Table: I'm wondering if there is a way to convert all my timestamps into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.