Welcome to WebmasterWorld Guest from 34.204.189.171

Forum Moderators: open

Message Too Old, No Replies

Posting only one line of data where multiple results are possible

     
5:21 am on Jul 6, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2008
posts:45
votes: 0


I have a simple search that is supposed to search a MySQL table and then return the data. The problem is that there is alot of repetive lines that I don't want to be displayed in the result. So what I need to happen is for only like the first line where (for example) title=wow

What I don't want:
green ¦ house ¦ two ¦ yes ¦ 1991
yellow ¦ house ¦ one ¦ yes ¦ 1973
blue ¦ house ¦ one ¦ no ¦ 1995
green ¦ trailer ¦ one ¦ no ¦ 2001
blue ¦ trailer ¦ one ¦ yes ¦ 2000

What I do want displayed:
green ¦ house ¦ two ¦ yes ¦ 1991
green ¦ trailer ¦ one ¦ no ¦ 2001

Thanks in advance!

4:26 pm on July 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Not sure I understand, your data example could be

select * from table where color='green';

but your question

what I need to happen is for only like the first line

could be several things. Given what you've asked, you could do

select * from table where color='green' order by some_field limit 1;

But most often when this is asked, it's a result of a join. So you could do several things, based on what you're looking for.

Distinct field, in a data set where there are multiple values:

select distinct(rec_id),* from table where color='green';

select table.* from table,join_table where table_id=join_table.join_field;

or

select * from table left join join_table on join_field=rec_id where table.color='green';

11:11 pm on July 6, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2008
posts:45
votes: 0


hmm well i solved it!

thanks for the help though!