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 7614073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:18:37+00:00 2026-05-31T02:18:37+00:00

I am experimenting with a test database to learn SQL, (MySQLi PHP) I am

  • 0

I am experimenting with a test database to learn SQL, (MySQLi PHP)

I am pulling data from two tables add_images and item where the primary key for ‘item’ is referenced as the foreign key in ‘add_images’. One ‘item’ will only has one image (add_images).

I need to get specific details about an item referenced by it’s image_name.

I only have one entry in the database under d7.jpg which is of type VARCHAR. When I run the below query I get 34 results where I should only get one? why is this?

This also happens when I run the query in phpmyadmin

Here is the query

SELECT item_name, catagory, brand, store, location, month, year, details FROM add_images, item WHERE add_images.image_name='d7.jpg '

I think I am doing something fundamentallly wrong here in the way I have my tables configured?

Hope someone can advise!

Thanks

below are the two tables

CREATE TABLE IF NOT EXISTS `add_images`( `image_id` int(10) unsigned NOT NULL     AUTO_INCREMENT COMMENT 'unique id for an image',
  `item_id` int(10) unsigned NOT NULL COMMENT 'unique id for the item been added',
  `image_name` varchar(20) NOT NULL COMMENT 'name of the image',
  `type` enum('standard','deleted','profile','look','item') NOT NULL COMMENT 'status and       type of image',
  `date_added` varchar(50) NOT NULL COMMENT 'date image was added',
  PRIMARY KEY (`image_id`),
  UNIQUE KEY `item_id` (`item_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COMMENT='Add images to item or profile picture'     AUTO_INCREMENT=50 ;


CREATE TABLE IF NOT EXISTS `item` (
 `item_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key for item',
 `item_name` varchar(20) NOT NULL COMMENT 'title name of the item',
 `catagory` enum('accessories','jackets','coats','footwear','legwear','jeanswear','dresses','shirts','tops','t-shirts','knitwear','skirts','shorts') NOT NULL COMMENT 'item catagory',
 `brand` varchar(20) NOT NULL COMMENT 'brand of product',
 `store` varchar(20) NOT NULL COMMENT 'store the item was purchased',
 `location` varchar(20) NOT NULL COMMENT 'location the item was purchased',
 `month` enum('January','February','March','April','May','June','July','August','September','October','November','December') NOT NULL COMMENT 'month the item was purchased',
 `year` int(2) NOT NULL COMMENT 'year the item was purchased',
 `details` varchar(500) NOT NULL COMMENT 'details about the item description',
 `date` varchar(50) NOT NULL COMMENT 'date item created',
 PRIMARY KEY (`item_id`),
 UNIQUE KEY `item_id` (`item_id`)
)    ENGINE=InnoDB  DEFAULT CHARSET=latin1 COMMENT='holds data about the item'     AUTO_INCREMENT=72 ;
  • 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-05-31T02:18:38+00:00Added an answer on May 31, 2026 at 2:18 am

    Your query does a join but does not put any condition in the WHERE clause on the item table, so the query will combine all item entries with the add_images result no matter if the item_id matches. You’ll want to change your query to reflect that;

    SELECT item_name, catagory, brand, store, location, month, year, details 
    FROM add_images, item 
    WHERE add_images.image_name='d7.jpg '
      AND item.item_id = add_images.item_id;
    

    EDIT: If you rewrite the query as an explicit join, it’s easier to see if you’re missing a link between the tables;

    SELECT item_name, catagory, brand, store, location, month, year, details 
    FROM add_images
    JOIN item ON item.item_id = add_images.item_id   -- ON specifies the link
    WHERE add_images.image_name='d7.jpg ';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Experimenting with Asynchronous Mail 0.2.1 using Oracle as backing database. Running small test app
I'm experimenting with DIVs to align my page's contents: http://labs.pieterdedecker.be/test/test.htm As you can see,
I am experimenting with NHibernate (version 2.1.0.4000) with Fluent NHibernate Automapping. My test set
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
Item 2 of the Joel Test is Can you make a build in one
I'm experimenting with OpenSSL on my network application and I want to test if
I am experimenting with some css3 transitions. I put together a quick slider test
I have been experimenting with using UUIDs as database keys. I want to take
I am experimenting with using xml as a database for small CMS, like gallery
I'm experimenting with Dll rebasing on a small test solution running on .net4 consisting

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.