User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 374,181 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,414 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 374 | Replies: 7
Reply
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

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

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Raleigh, NC
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

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

  #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  
Join Date: Dec 2007
Posts: 102
Reputation: mwasif is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 12
mwasif mwasif is offline Offline
Junior Poster

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

  #3  
Apr 13th, 2008
Double post.
Last edited by mwasif : Apr 13th, 2008 at 11:34 am.
Reply With Quote  
Join Date: Dec 2007
Posts: 102
Reputation: mwasif is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 12
mwasif mwasif is offline Offline
Junior Poster

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

  #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  
Join Date: Apr 2008
Posts: 10
Reputation: swingingstars is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
swingingstars swingingstars is offline Offline
Newbie Poster

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

  #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 2:56 am.
Reply With Quote  
Join Date: Dec 2007
Location: Raleigh, NC
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

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

  #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  
Join Date: Apr 2008
Posts: 10
Reputation: swingingstars is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
swingingstars swingingstars is offline Offline
Newbie Poster

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

  #7  
Apr 18th, 2008
heh? what do you mean?
Reply With Quote  
Join Date: Dec 2007
Location: Raleigh, NC
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

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

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

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 4:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC