Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join two queries in a datagrid

Status
Not open for further replies.
Jun 25, 2007
2
MX
Hi guys I have one TDBgrid ... and I have two queries with the same fields *but* from different tables ... how do i join those two queries (TQueries) in one DBGrid (TDBgrid)

Thanks (Miguel)
 
you have a single TQuery and use a UNION:

Code:
SELECT Field1, Field2, Field3 FROM Table1
UNION
SELECT FIeld4, FIeld5, Field6 FROM Table2[code]

You can even add an indicator to show WHERE the data came from in case you need to do some kind of edit or update:

[code]SELECT Field1, Field2, Field3, 'Table1' As Location FROM Table1
UNION
SELECT FIeld4, FIeld5, Field6, 'Table1' FROM Table2[code]



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers: 
[url=http://www.alphabetcitydataworks.com/fundamentals.htm]The Fundamentals of Relational Database Design[/url]
[url=http://www.devshed.com/c/a/MySQL/Understanding-SQL-Joins]Understanding SQL Joins[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top