March 12, 2012

SELECT command in mysql

Question by Jordashiro

I was wondering if there is a way to do something like selecting all without … some columns here

something like SELECT */column1,column2 , is there a way to do this ?
I just need to output something like

column1 , column2 ( from another table ) , here all other columns without column1 ( or something to make the select skip the first few columns)

EDIT:
The thing is that i need this to be dynamic , so i cant just select what i don’t know. I never know how many columns there will be , i just know the 1st and the 2nd column

EDIT: here is a picture http://oi44.tinypic.com/xgdyiq.jpg
I don’t need the second id column , just the last column like i have pointed.

Answer by DanRedux

Oh, so select all but certain fields. You have two options.

One is a little slow.. Copy the table, drop the fields you don’t want, then SELECT *
The other is to build the field list from a subquery to information_schema or something, then remove occurrences of ‘field_i_dont_want’ in that list.

SELECT ( SELECT THE TABLES YOU WANT AND CONCAT INTO ONE STRING ) FROM TABLE

Answer by Starx

If you need to combine records from multiple tables, you need to find a way to relate them together. Primary Keys, Foreign Keys, or anything common among this.

I will try to explain this with a sql similar to your problem.

SELECT table1.id, table2.name, table1.column3, table1.column4 
FROM table1
INNER JOIN table2 On table2.commmonfield = table1.commonfield

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!