0

SQL Quires is displaying multiple values

i mean if sql query actually out put is like this :

10456123   4561265    12   13   45  55   66
45869655   4556446    99   56   45  45   45

it is displaying as :

10456123   4561265    12   13   45  55   66
45869655   4556446    99   56   45  45   45
10456123   4561265    12   13   45  55   66
45869655   4556446    99   56   45  45   45

It is Showing DOUBLE times (2times)

10
  • 6
    You are actually executing two queries and printing out the results of both. Could it be that both actually have the same result? Commented Aug 23, 2013 at 14:10
  • @UlrichSchmidt-Goertz i used 2 quires because, i didn't know understand how to do this in a single query :( Commented Aug 23, 2013 at 14:14
  • Ok, I see. Well, have you tried executing the query (it would be $sql) on the database directly? Commented Aug 23, 2013 at 14:17
  • Did you try running the queries directly in MySQL or some tool like phpMyAdmin and see what the results are? Maybe your query is wrong and it is giving duplicate results. Commented Aug 23, 2013 at 14:17
  • maybe 32r07.htno have identical values? Check that Commented Aug 23, 2013 at 14:19

2 Answers 2

1

Try adding DISTINCT:

SELECT DISTINCT * 
  FROM 32r07,
       32r07names 
 WHERE 32r07.htno = 32r07names.htnon 
   AND 32r07.htno = '$name'

SELECT DISTINCT * 
  FROM 32r07names 
 WHERE htnon = '$name'

This is not plroblem solver, but it will help. also, DO NOT use *. I think you need to check for duplicate values in tables.

Sign up to request clarification or add additional context in comments.

3 Comments

i'm sure there are no duplicate values. you said ` DO NOT use *` did this mean, should i write all column names there with (comma) separated..
there are no duplicate values... is there any change that this can be done in a single query... i used this (32r07.htno = 32r07names.htnon ) just to check that the input is in both tables....
Yes, I mean write all columns. Try query in SQL Developer first. Do you found problem?
0

You are actually executing (almost) the same query twice:

SELECT * FROM 32r07, 32r07names WHERE 32r07.htno = 32r07names.htnon AND 32r07.htno = '$name';

could be rewritten as

SELECT * FROM 32r07 INNER JOIN 32r07names ON htno = htnon WHERE 32r07.htno = '$name';

The second query being

SELECT * FROM 32r07names WHERE htnon = '$name';

Which is like saying, altogether:

... WHERE htnon = htno = '$name';

2 Comments

this didn't help :( i tried SELECT * FROM 32r07 INNER JOIN 32r07names ON htno = htnon WHERE 32r07.htno = '$name'; but same :(
Yes, you should use one query, not both. Try adding more data, specially data that would show up using one query but not the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.