Jump to content

[SOLVED] Find records from all my database with a criteria


mattyvx

Recommended Posts

All,

 

Currently I have a list of tables within my database, within these tables is information about site members. The last column of every table is called "Featured" and will either have a y or n value in it.

 

What i want is to run a query on all my tables (new tables added daily) and return only records which are featured (marked by a y in the featured feild).

 

I can get this to work for searching one table but i want ALL tables to be searched (without manually coding seperate queries for each table).

 

Maybe something like....

 

[sELECT * FROM TABLES WHERE ["Featured"] = y]

 

Thanks in advance!

Link to comment
Share on other sites

thanks, i was hoping i wouldn't have to do that....

 

Is there no way to code in such a way that the number of tables is a variable?

 

So just search EVERY TABLE within my databse "customers". Im basically after an automated script so that regardless of how many tables i have it searches them all. The number of tables is always increasing and id rather not have to amend the script every time i add a table.

 

*Lazy i know, but id rather the code do the work for me :)*

Link to comment
Share on other sites

The number of tables is always increasing
That indicates a bad design, as you just found out, because it makes it difficult to find the same type of information in more than a single table. There is no table 'wild card' that you can put into a single query. You must either loop through all the tables or form a UNION query as has been shown in the posts above.

 

A correct database design would put the same type of data into one table. Whatever value that is different between that data now that you are using to cause separate tables would simply become a value in a 'catagory' column in a single table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.