944,119 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 30586
  • MySQL RSS
May 28th, 2005
0

MySQL query to loop through results distinctly

Expand Post »
Hey, I am having a really stupid yet annoying problem.

I have a simple database stracture (I'll give an example below) and I want to do a query that will loop through it's elements trying to display the list amount of times each element (trying to make it the most unique it can).


Example for the database:

field 1 | field 2
-------------------
| A_name | A_meow |
-------------------
| A_name | mrgao |
-------------------
| esea | fafas |
-------------------
| A_name | mrewo |
-------------------
| esea | wahod |
-------------------

I want to do a query that will look something like this (it's not real query)
SELECT * FROM `table` LOOP `field 1` LIMIT 4
and the output would be like this:
-------------------
| A_name | A_meow |
-------------------
| esea | fafas |
-------------------
| A_name | mrgao |
-------------------
| esea | wahod |
-------------------

notice how it looped through the field 1 but not the others, that's what I wanna do but I can't figure how!!!!!!!

the closest thing I can do is SELECT DISTINCT(`field 1`), * FROM `table` LIMIT 4
but than I will not recive 4 results like I want, I will recive the amount of distincted field 1 values.

I hope I didn't complex you with the way I asked it but it would really help me if you find a way to do it!

Thanks, Omri.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
OmriA is offline Offline
1 posts
since May 2005
Jun 1st, 2005
0

Re: MySQL query to loop through results distinctly

i think you should try T-SQL and loops in them, you can find its documents on http://dev.mysql.com/doc/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chagh is offline Offline
5 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Problem writing to DB can someone take a look at my query string??
Next Thread in MySQL Forum Timeline: MySQL Question(s)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC