| | |
MySQL query to loop through results distinctly
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2005
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: May 2005
Posts: 5
Reputation:
Solved Threads: 0
i think you should try T-SQL and loops in them, you can find its documents on http://dev.mysql.com/doc/
![]() |
Similar Threads
- test mysql query for no results (PHP)
- Double MySQL Query (PHP)
- Python Tuples and Mysql Query (MySQL)
- MySQL query's (MySQL)
- Change MySQL Query Timeout Period (MySQL)
- pagination of mysql query results (PHP)
- SQL search query (PHP)
Other Threads in the MySQL Forum
- Previous Thread: Problem writing to DB can someone take a look at my query string??
- Next Thread: MySQL Question(s)
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





