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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:33:38+00:00 2026-06-01T04:33:38+00:00

I had a table like this id | name —————— 1 | SAM1 2

  • 0

I had a table like this

id   |   name 
------------------
1    |   SAM1
2    |   SAM2
1    |   SAM1
3    |   SAM3
7    |   SAM7
6    |   SAM6

I need to show the results using this query

SELECT name,id FROM tblnameWHERE id IN (1,2,7,6,1)

and getting the following result

id   |   name 
------------------
1    |   SAM1
2    |   SAM2
7    |   SAM7
6    |   SAM6

My problem is this skipped last id , ie 1 . I need something like this

id   |   name 
------------------
1    |   SAM1
2    |   SAM2
7    |   SAM7
6    |   SAM6
1    |   SAM1

With out using the loop query ( like follows ) any other method for doing this ?

$ids=array(1,2,7,6,1);
$i=0;
foreach($ids as $id){

$sql=mysql_query("SELECT * FROM tblname WHERE id=$id");
// Store value to array 

}

Please 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-01T04:33:39+00:00Added an answer on June 1, 2026 at 4:33 am

    The query

    SELECT name,id FROM tblname WHERE id IN (1,2,7,6);
    

    should show duplicate rows; e.g. if there are really in the table two distinct rows with the very same id, then the query will show them (since there’s no DISTINCT keyword).

    Instead, if you want to create duplicate lines starting from a table containing single lines, you have to join your table with a table having repeated 1 (in your case); another way could be to use union like this:

    SELECT  name, id FROM tblname WHERE id IN (1,2,7,6)
      UNION ALL
    SELECT name, id FROM tblname WHERE id = 1;
    

    Edit

    Since your id is a primary key, it will be unique, hence the “problem” you’re experiencing. If you want to allow duplicate rows on insert, remove the primary key. If you need it, consider the possible solutions suggested above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table that looks like this: id (int primary) name (text)
If I had a SQL Server table that looks something like this with some
If I had a CarsDataStore representing a table something like: Cars -------------- Ford |
I previously had a table that is created using hibernate entities. I am using
I am using Microsoft SQL Server. I have a Table which had been updated
I have two tables that look like this: Products: id category name description active
I had a mysql table called events with the fields: id, date, and name.
I have a DataGridView binded to this table: [Users] ID Name -- ---- 11
Ive never had to use a query like this before but there must be
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,

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.