Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010

    How to join search result in one query on mutil table

    Hi everyone.

    I have a not difficult issue, however, I do not know how to implement it.

    my case is:

    I have two table. table_A, table_B,
    table_a {id, name}
    table_b {id, address}
    what i am want to do is:

    i want to find some text in both table with in column name or address.
    maybe you will ask me why not create one table, sorry, there is some reason there.

    let me continue my case, for example, I want to search record with text: mike.

    select from table_A where name like "text%"
    select B.address from table_B where address like "text%"

    is there a way to query both table at same time.

    select, B.address from table_A, table_b where like "text%" or B.address like "text%" and !=;


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    Quote Originally Posted by DBConfuser View Post
    is there a way to query both table at same time.
    yes, with a union query
    SELECT AS found_column
         , 'A'    AS found_table
      FROM table_A AS A
     WHERE name LIKE 'text%'
    SELECT B.address 
         , 'B'
      FROM table_B AS B
     WHERE address LIKE 'text%' | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2010


    that was awesome,

    and it works great.

    Thanks R937.

    if i want to remove the same ID record. how to do it?

    sorry I am new pie for database and so greedy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts