DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   Can i retrive different fields of a record as one result. (http://www.daniweb.com/forums/thread118731.html)

jino Apr 12th, 2008 2:14 am
Can i retrive different fields of a record as one result.
 
Dear All,

I am new to MySQL. Can i retrive the result of a query as the combination of different fields of a single record..

For example..
if the result record of a query is ... id(1), country(India), Location1(maharashtra), Location2(pune), Location3(Navi Mumbai)...

My doubt is that can i retrive the 3 locations as one field..

Please excuse me if this is a foolish question..

Regards,

Jino..

AaronASterling Apr 12th, 2008 11:57 am
Re: Can i retrive different fields of a record as one result.
 
if they are all coming from a single table...call it testTable... then you would just say

SELECT location1, location2, location3 FROM testTable  WHERE ....

and then you can fill in whatever goes in the WHERE clause to get the result you want. In general you can list as many fields as you want plus other goodies in the select expression (the part where you tell it what you want) of a SELECT statement. They have to seperated by commas.

mwasif Apr 13th, 2008 11:33 am
Re: Can i retrive different fields of a record as one result.
 
Double post.

mwasif Apr 13th, 2008 11:33 am
Re: Can i retrive different fields of a record as one result.
 
You can use CONCAT()/CONCAT_WS() functions to get as many fields as you want as a single column.

SELECT id, CONCAT(', ', location1, location2, location3) FROM table

swingingstars Apr 18th, 2008 2:55 am
Re: Can i retrive different fields of a record as one result.
 
Quote:

Originally Posted by AaronASterling (Post 583153)
if they are all coming from a single table...call it testTable... then you would just say

SELECT location1, location2, location3 FROM testTable  WHERE ....

and then you can fill in whatever goes in the WHERE clause to get the result you want. In general you can list as many fields as you want plus other goodies in the select expression (the part where you tell it what you want) of a SELECT statement. They have to seperated by commas.




that's exactly what i've been using

SELECT location1 a, location2 b , location3 c FROM testTable  WHERE  a.someField = b.someOtherField AND b.someOtherField = c.someOtherFieldToo


OR LIKE THIS :

SELECT location1 a LEFT JOIN location2 b ON  a.someField = b.someOtherField WHERE someOtherField = 'blabla'

AaronASterling Apr 18th, 2008 7:13 am
Re: Can i retrive different fields of a record as one result.
 
Oh. So thats what it feels like to look like an idiot. I forget if I go more then 20 minutes without putting my foot in my mouth. I'll read more carefully next time

swingingstars Apr 18th, 2008 7:31 am
Re: Can i retrive different fields of a record as one result.
 
heh? what do you mean?

AaronASterling Apr 18th, 2008 8:05 am
Re: Can i retrive different fields of a record as one result.
 
i answered a different question. Should have read the question better. mwasif got it right


All times are GMT -4. The time now is 11:13 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC