Statement This SQL statement can query two different fields of different structures and can tell which records belong to which table
has two tables
The Table1 structure is as follows
ID Title Content
The table2 structure is as follows
ID content Bigclass Smallclass
sql= "SELECT ID, title, content, ' as Bigclass, ' as Smallclass, ' Tbl1 ' as tbl from table1 where title like '% ' &keyword &% ' or content like '% ' &keyword& '% ' union select ID, ' as title, Content,bigclass,smallclass, ' tbl2 ' as tbl From table2 where content like '% ' &keyword& '% ' ORDER by id DESC '
This statement allows you to implement the query.
For example, in ASP, the
Set Rs=conn.execute (SQL)
While not rs.eof
......
......
Response.Write rs ("tbl") ' This value is to determine which table the data is
......
......
Rs.movenextwend
Analysis of the above SQL statements, in fact, through as the two tables in the field name uniform, the number of fields is not enough in the (') brackets, that is, empty strings replaced, of course, if you are willing to also use a non-empty string instead (' This is bigclass belong to Table2 '), This also makes it easy to distinguish between the data in which table. This SQL statement cleverly uses the ' tbl1 ' as TBL to determine which table the statement belongs to, in order to process the data, especially for site search, search for different tables in a page display results, according to different tables to different ID values to different tables corresponding to the display page, Some want to use readnews.asp some to use other.asp this kind of page, use up very convenient.
Welcome everybody to discuss together!