On May 08, 2006, at 8:18 PM, Ed Lee wrote:

Hi folks:

Off topic, but I'm wondering if anyone has any idea of how to include table names in the result set of a UNION-like query to a MySQL DB?

I'm running with a query like this:

userRes = lasermgt.SQLSelect("Select * from reservations where fldTimestamp between '" + beforeToday.SQLDate + " 00:00:00' and '" + beforeToday.SQLDate + " 23:59:59' UNION Select * from deletedreservations where fldTimestamp between '" + beforeToday.SQLDate + " 00:00:00' and '" + beforeToday.SQLDate + " 23:59:59' order by fldTimestamp")

Since that's waaaaaay too complicated to follow, I'll clear it up a bit.

This translates into:

Select * from reservations where fldTimestamp between 'SQLDateTime' and 'SQLDateTime' UNION Select * from deletedreservations where fldTimestamp between 'SQLDateTime' and 'SQLDateTime' order by fldTimestamp;

reservations and deletedreservations are two individual tables in my database. They have identical schema.

The idea here is to return a set of results from the two tables that includes a field indicating which table it came from.

Is there an easy way to do this, or so I need to look outside of SQL commands to accomplish it?

Neither.
Simply create an extra derived column that tells you which table it came from

Select "reservations" as tblName , * from reservations where fldTimestamp between 'SQLDateTime' and 'SQLDateTime' UNION Select "deleted" as tblName, * from deletedreservations where fldTimestamp between 'SQLDateTime' and 'SQLDateTime' order by fldTimestamp;

i've not tried this but it should be possible to do this in a union in mySQL

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to