Can i retrive different fields of a record as one result.

Reply

Join Date: Feb 2008
Posts: 78
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Can i retrive different fields of a record as one result.

 
0
  #1
Apr 12th, 2008
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..
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Solved Threads: 5
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #2
Apr 12th, 2008
if they are all coming from a single table...call it testTable... then you would just say

  1. 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.
Aaron Sterling
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 190
Reputation: mwasif is an unknown quantity at this point 
Solved Threads: 25
mwasif mwasif is offline Offline
Junior Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #3
Apr 13th, 2008
Double post.
Last edited by mwasif; Apr 13th, 2008 at 12:34 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 190
Reputation: mwasif is an unknown quantity at this point 
Solved Threads: 25
mwasif mwasif is offline Offline
Junior Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #4
Apr 13th, 2008
You can use CONCAT()/CONCAT_WS() functions to get as many fields as you want as a single column.

  1. SELECT id, CONCAT(', ', location1, location2, location3) FROM table
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 17
Reputation: swingingstars is an unknown quantity at this point 
Solved Threads: 1
swingingstars swingingstars is offline Offline
Newbie Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #5
Apr 18th, 2008
Originally Posted by AaronASterling View Post
if they are all coming from a single table...call it testTable... then you would just say

  1. 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

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

OR LIKE THIS :

  1. SELECT location1 a LEFT JOIN location2 b ON a.someField = b.someOtherField WHERE someOtherField = 'blabla'
Last edited by swingingstars; Apr 18th, 2008 at 3:56 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Solved Threads: 5
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #6
Apr 18th, 2008
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
Aaron Sterling
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 17
Reputation: swingingstars is an unknown quantity at this point 
Solved Threads: 1
swingingstars swingingstars is offline Offline
Newbie Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #7
Apr 18th, 2008
heh? what do you mean?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Solved Threads: 5
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

Re: Can i retrive different fields of a record as one result.

 
0
  #8
Apr 18th, 2008
i answered a different question. Should have read the question better. mwasif got it right
Aaron Sterling
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC