473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to get field names from multiple tables in a single query

I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect the tables together with various queries using a unique id. My task is to generate reports from these tables dynamically. The user will select the data they want to see and the script will export a spreadsheet containing this data. I've got the front end completed (eg. the GUI they will use to select the data from the tables). I've got the export part completed (eg. the part that formats the data appropriately and exports it to a spreadsheet). I've got most of the rest of the script ready to go as far as sanitizing the input, building the queries, and pulling the data. The part I'm stuck on is this:

I do not know ahead of time what tables or columns will be selected. In order to build my queries, I need to get a list of the available columns from the selected tables. I've only found one way of accomplishing this task and that is to use "SHOW COLUMNS FROM table_name" on all the selected tables and push them into an array. This is horribly inefficient and I am hoping that someone may have a better way.

What I'm looking for is a way to combine these two statements:
DEFINE (SELECT * FROM table1,table2,table3,etc.)
and
SHOW COLUMNS FROM table_name

I've tried to join and union the SHOW COLUMNS but that produces an error and so does the same thing using DEFINE table_name.

Is there a way to select all the field names from multiple tables in a single query?
Jul 27 '07 #1
4 8844
mwasif
802 Expert 512MB
Moved from MySQL Articles to MySQL Forum. Kindly ask your MySQL related questions in MySQL Forum.
Jul 28 '07 #2
mwasif
802 Expert 512MB
If you have MySQL 5 try INFORMATION_SCHEMA.
Jul 28 '07 #3
Unfortunately, I'm stuck with MySQL 4.1.14 and cannot upgrade (shared hosting account). Otherwise, your suggestion would easily work. Thanks for taking the time to respond though.

ps. Oops...didn't realize I was putting this in as an article. Will pay more attention next time.
* img.lightbulb { cursor: pointer; }
img.lightbulb { cursor: pointer; }
Aug 4 '07 #4
If anyone like me is still looking for a solutions to this problem, what I did was: once I did the query (any) I look up through the result record as an array. The key values are the columns names. That works in PHP :)
Aug 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
6
by: kcddoorman | last post by:
I built a select query filled with fields from multiple tables and queries. I have one field in this particluar query that will filter out a single order number. In the criteria box I put and that...
11
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I...
10
by: H | last post by:
Hi, I have the following address fields in a table: flat_number house_name_or_number street village postal_town county postcode
1
by: jaceyk | last post by:
Is it even remotely possible to update field names to the correct field name for the same table using a data definition query? We have a utility that spits out data in an Access database for use in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.