Professional Web Applications Themes

Retrieve fields with similar values from 2 tables? - MySQL

Hi, How do i retreive fields with similar values from 2 tables? I tried to use "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'"; but it doesn't retrieve similar names from the 2 tables. However, "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like p.name"; will retrieve only names that match exactly, but this is not what i want. Any advice will be appreciated. TIA...

  1. #1

    Default Retrieve fields with similar values from 2 tables?

    Hi,

    How do i retreive fields with similar values from 2 tables?

    I tried to use
    "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'";
    but it doesn't retrieve similar names from the 2 tables.

    However,
    "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like p.name";
    will retrieve only names that match exactly, but this is not what i want.

    Any advice will be appreciated.

    TIA




    no.mail.pls Guest

  2. #2

    Default Re: Retrieve fields with similar values from 2 tables?

    "no.mail.pls" <no.mailst.peters> wrote in message
    news:441a4132$0$15790$14726298news.sunsite.dk...
    > I tried to use
    > "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'";
    This is close, but putting p.name inside the quotes make it use the string
    'p.name', instead of the value of that field. Try the following:

    SELECT * FROM $table1 as o , $table2 as p
    WHERE o.name LIKE CONCAT('%', p.name, '%');

    Regards,
    Bill K.


    Bill Karwin Guest

  3. #3

    Default Re: Retrieve fields with similar values from 2 tables?

    "Bill Karwin" <billkarwin.com> wrote in message
    news:dvdg9s02pkenews3.newsguy.com...
    > "no.mail.pls" <no.mailst.peters> wrote in message
    > news:441a4132$0$15790$14726298news.sunsite.dk...
    >> I tried to use
    >> "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'";
    >
    > This is close, but putting p.name inside the quotes make it use the string
    > 'p.name', instead of the value of that field. Try the following:
    >
    > SELECT * FROM $table1 as o , $table2 as p
    > WHERE o.name LIKE CONCAT('%', p.name, '%');
    >
    > Regards,
    > Bill K.
    Thanks Bill, but it still doesn't work.

    The command
    SELECT * FROM $table1 as o , $table2 as p WHERE o.name LIKE CONCAT('%',
    p.name, '%');
    will retrieve exact matches only.

    The command
    "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'";
    will retrieve nothing at all.

    Any advice will be appreciated.

    TIA



    no.mail.pls Guest

  4. #4

    Default Re: Retrieve fields with similar values from 2 tables?

    "no.mail.pls" <no.mailst.peters> wrote in message
    news:441a4dc9$0$15782$14726298news.sunsite.dk...
    > SELECT * FROM $table1 as o , $table2 as p WHERE o.name LIKE CONCAT('%',
    > p.name, '%');
    > will retrieve exact matches only.
    Give examples of values that you want to be considered matches, but aren't
    when queried with the above criteria.

    Regards,
    Bill K.


    Bill Karwin Guest

  5. #5

    Default Re: Retrieve fields with similar values from 2 tables?

    "Bill Karwin" <billkarwin.com> wrote in message
    news:dvdp6l0he3enews3.newsguy.com...
    > "no.mail.pls" <no.mailst.peters> wrote in message
    > news:441a4dc9$0$15782$14726298news.sunsite.dk...
    >> SELECT * FROM $table1 as o , $table2 as p WHERE o.name LIKE CONCAT('%',
    >> p.name, '%');
    >> will retrieve exact matches only.
    >
    > Give examples of values that you want to be considered matches, but aren't
    > when queried with the above criteria.
    >
    > Regards,
    > Bill K.
    Hi,

    A solution was posted by

    "Jake Krohn" <krohnkece.cmu.edu> wrote in message
    news:dvehtp$5se$1nntp.ece.cmu.edu...
    >> How do i retrieve fields with similar values from 2 tables?
    >>
    >> I tried to use
    >> "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like
    >> '%p.name%'";
    >> but it doesn't retrieve similar names from the 2 tables.
    >>
    >> However,
    >> "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like p.name";
    >> will retrieve only names that match exactly.
    >
    > Try this:
    >

    SELECT * FROM table1 a, table2 b
    WHERE INSTR(a.name, b.name) <> 0

    Jake Krohn


    no.mail.pls Guest

Similar Threads

  1. Retrieve Form Names and values
    By DavidGuy_Houston_TX in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: August 10th, 03:13 AM
  2. Unable to retrieve tables over Mac to PC databaseconnection
    By Eddy Miller in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 29th, 07:21 PM
  3. Unable to retrieve tables from connection
    By john@blastoffnow.com in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 27th, 12:46 PM
  4. how to update and retrieve ntext fields in my asp code
    By el_sherif in forum ASP Database
    Replies: 3
    Last Post: July 31st, 07:38 PM
  5. How to retrieve the values of the previous row during ItemDataBound
    By adiel in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: July 17th, 06:29 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139