SQL statement

admin

Administrator
Staff member
Do anyone know how to write an SQL statement to search from one table to another table without having any relationship or any common key. Because I am creating a search page where I need to search the information from the two tables (both of the tables are storing the similar thing - one is to store user with the read function while the other is to store user with the read and write function)without anything common...that sql query will return alot unneccessary records.

u can do this.

select a.*, b.* from tableA a, tableB b where a.xxx = 'xxx' and b.yyy = 'yyy'

but you will every b.* rows for every a.* row...

meaning, if you have 5 rows in tableB...an 3 rows in tableA..

you will get something like this.

row1_inTableA---row1_inTableB
row1_inTableA---row2_inTableB
row1_inTableA---row3_inTableB
row1_inTableA---row4_inTableB
row1_inTableA---row5_inTableB
row2_inTableA---row1_inTableB
row2_inTableA---row2_inTableB
row2_inTableA---row3_inTableB
row2_inTableA---row4_inTableB
row2_inTableA---row5_inTableB
row3_inTableA---row1_inTableB
row3_inTableA---row2_inTableB
row3_inTableA---row3_inTableB
row3_inTableA---row4_inTableB
row3_inTableA---row5_inTableB

or u can form it in 2 queries, and execute it once and get 2 result set.

-TakSorry takkie, the SQL statement that you have given earlier i think it is not working as what i wanted bec the result that it return is only from one table rather than from both of the table. DO you or anyone else know how to write the SQL Statement

thank in advanceYou could use a UNION SELECT statement like this. SELECT username, password FROM tableA WHERE username = 'username' UNION SELECT Username, password FROM tableB WHERE username = 'username';
 
Back
Top