| | |
Can i retrive different fields of a record as one result.
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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..
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.
if they are all coming from a single table...call it testTable... then you would just say
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.
SQL Syntax (Toggle Plain Text)
SELECT location1, location2, location3 FROM testTable WHERE ....
Aaron Sterling
•
•
Join Date: Dec 2007
Posts: 190
Reputation:
Solved Threads: 25
You can use CONCAT()/CONCAT_WS() functions to get as many fields as you want as a single column.
sql Syntax (Toggle Plain Text)
SELECT id, CONCAT(', ', location1, location2, location3) FROM table
•
•
Join Date: Apr 2008
Posts: 17
Reputation:
Solved Threads: 1
•
•
•
•
if they are all coming from a single table...call it testTable... then you would just say
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.SQL Syntax (Toggle Plain Text)
SELECT location1, location2, location3 FROM testTable WHERE ....
that's exactly what i've been using
SQL Syntax (Toggle Plain Text)
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)
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.
![]() |
Other Threads in the MySQL Forum
- Previous Thread: urgent reply.. mysql bug... about queries date using MySQL
- Next Thread: please help me with this
| Thread Tools | Search this Thread |
agplv3 amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





