943,852 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1015
  • MySQL RSS
Apr 12th, 2008
0

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

Expand Post »
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..
Reputation Points: 10
Solved Threads: 10
Junior Poster
jino is offline Offline
114 posts
since Feb 2008
Apr 12th, 2008
0

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

SQL Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 5
Light Poster
AaronASterling is offline Offline
31 posts
since Dec 2007
Apr 13th, 2008
0

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

Double post.
Last edited by mwasif; Apr 13th, 2008 at 12:34 pm.
Reputation Points: 29
Solved Threads: 47
Posting Whiz
mwasif is offline Offline
312 posts
since Dec 2007
Apr 13th, 2008
0

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.

sql Syntax (Toggle Plain Text)
  1. SELECT id, CONCAT(', ', location1, location2, location3) FROM table
Reputation Points: 29
Solved Threads: 47
Posting Whiz
mwasif is offline Offline
312 posts
since Dec 2007
Apr 18th, 2008
0

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

SQL Syntax (Toggle Plain Text)
  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

SQL Syntax (Toggle Plain Text)
  1. SELECT location1 a, location2 b , location3 c FROM testTable WHERE a.someField = b.someOtherField AND b.someOtherField = c.someOtherFieldToo

OR LIKE THIS :

SQL Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
swingingstars is offline Offline
17 posts
since Apr 2008
Apr 18th, 2008
0

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
Reputation Points: 10
Solved Threads: 5
Light Poster
AaronASterling is offline Offline
31 posts
since Dec 2007
Apr 18th, 2008
0

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

heh? what do you mean?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
swingingstars is offline Offline
17 posts
since Apr 2008
Apr 18th, 2008
0

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
Reputation Points: 10
Solved Threads: 5
Light Poster
AaronASterling is offline Offline
31 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: urgent reply.. mysql bug... about queries date using MySQL
Next Thread in MySQL Forum Timeline: please help me with this





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC