RE: Mysql Query Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Imran,
I am not too keen on the table design, because there is no unique id.

Anyway, due to this problem, you have to effectively code your way around
the inability to identify particular rows with something along the lines of:

select t1.id, t1.value, t2.value from tbl t1
inner join tbl t2 on t1.id=t2.id
where t1.id='bbb'
order by t1.id, t1.value limit 1

With the 'limit' at the end forcing the statement to return just one row.
But you have to ask yourself is that the row you wanted?  You don't know
because you can't tell the rows apart.  That may not matter in this case but
will become more and more significant if you try to add any more columns to
the table.

I think the key things to take on board from this example is firstly, always
have a unique key on your tables and secondly, joining a table to itself is
a useful technique for exposing an entity which has a relationship with
itself.

Brian

-----Original Message-----
From: imran rahi [mailto:imranforphp@xxxxxxxxx] 
Sent: 01 November 2005 06:27
To: phpexperts; NashikOOMD@xxxxxxxxxxxxxxx; php-objects@xxxxxxxxxxxxxxx;
PHP_MySQL_usergroup@xxxxxxxxxxxxxxx; php_gurus@xxxxxxxxxxxxxxx;
in-phpug@xxxxxxxxxxxxxxx
Subject:  Mysql Query Help

Hi
I am working in MySQL 5.
I came across a requirement. There is a table tbl having 2 columns id and
value. Having entries like

aaa 1
bbb 2
ccc 3
bbb 1

No i need the output for id 'bbb' as

bbb 2,1
 or
bbb 1,2

Can anybody get me the query to get such result. Its like getting comma
seperated values for a particular id.

Thanks in advance
Imran Rahi




		
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com



PHP Data object relational mapping generator - http://www.meta-language.net/

Yahoo! Groups Links



 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux