Jump to content


Photo

Missing Results returned in SQL??


  • Please log in to reply
2 replies to this topic

#1 tobestar

tobestar
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 December 2003 - 02:46 AM

I am having the most bizarre situation when I am trying to use DISTINCT or GROUP BY in a SQL query.

I have several suburbs in my table. Some of them repeat, and I am trying to display them in a list box. No problem...

I use

$result= MYSQL_QUERY(\"SELECT * FROM renovator);

and I get everything I need, but of course there are repeated values.

so...

$result= MYSQL_QUERY(\"SELECT DISTINCT suburb FROM renovator WHERE region = \'$region\' ORDER BY suburb ASC\");

great... works a treat, but there is a value(suburb) missing. No matter what I do, I cannot get all the values to show up.

AND...

$result= MYSQL_QUERY(\"SELECT DISTINCT suburb FROM renovator WHERE region = \'$region\'\");

returns a different set of values... with the suburb I needed present, but now a different suburb missing??

I have no idea what is going on.

PLEASE HELP!!! :cry:

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 17 December 2003 - 07:47 AM

Your SQL looks OK so I would look at the data, prticularly spellings of \'region\' (if it\'s alpha) or extra space char at end of one maybe.

Try
\"SELECT DISTINCT region, suburb FROM renovator ORDER BY region, suburb\"
and see if that throws up any clues.

hth
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 tobestar

tobestar
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 December 2003 - 11:20 PM

:o

I have discovered that the problem was a line in my PHP code.

Thank you very much for your reply anyway.

Have a great xmas.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users