Re: How to Query 2 Tables (Not a join?)
"The reason I have so many tables with all the same fields is that eventually (future expansion) after some growth, thesee tables will have fields added that are NOT the same."
Using * (the catch all columns identifier) will not work with union if the tables have different columns.
Assuming that each of your 50 tables has a column called 'level' and another called 'result', say, (maybe with some other columns as well), you can use the statement
select result from tablea where level=1 union select result from tableb union select result from tablec where level=1 ... order by reverse(rand()) limit 1;
This is going to get large and difficult to maintain for 50 tables.
Use a single table instead of having 50 - which would mean a much simpler select. You can add columns to a table in MySQL and others using 'alter table'.
If you had a single table then your statement would be
select result from mytable where level=1 order by reverse(rand()) limit 1;
Adding columns would not affect this statement.
__________________
There may be no such thing as a silly question but the world is littered with silly answers.
|