Professional Web Applications Themes

Column Number in Where Clause - MySQL

Hello, Is any way to access the column value using the number of the selected column in a select-where command? Ex: select name, lastName from custumer where fields[0] like '%smi%' or fields[1] like '%smi%'? If it is not possible, is any way to do a "like" foreach field selected in a easy way? Thanks...

  1. #1

    Default Column Number in Where Clause

    Hello,

    Is any way to access the column value using the number of the selected
    column in a select-where command?

    Ex:
    select name, lastName from custumer where fields[0] like '%smi%' or
    fields[1] like '%smi%'?

    If it is not possible, is any way to do a "like" foreach field
    selected in a easy way?

    Thanks

    Francisco Guest

  2. #2

    Default Re: Column Number in Where Clause

    Francisco Spaeth wrote: 

    Not really. And this would not be good, anyway - it would be dependent
    on the order of the columns. Adding a column at the beginning, for
    instance, would break your queries.

    And if you're storing similar information in multiple columns, you
    probably need to normalize your database - which would solve your query
    problem.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  3. #3

    Default Re: Column Number in Where Clause

    Ok, I understand the situation, but I want to do a select-where
    comparing a string with all fields in a fast way... like select * from
    table where any_column like '%smi%'... with numbered columns that wold
    be faster to control columns who is applied case structures or other
    structures...

    Is any way to do this?


    On 4 jul, 10:55, Jerry Stuckle <net> wrote: 




    >
    > Not really. And this would not be good, anyway - it would be dependent
    > on the order of the columns. Adding a column at the beginning, for
    > instance, would break your queries.
    >
    > And if you're storing similar information in multiple columns, you
    > probably need to normalize your database - which would solve your query
    > problem.
    >
    > --
    > ==================
    > Remove the "x" from my email address
    > Jerry Stuckle
    > JDS Computer Training Corp.
    > net
    > ==================[/ref]


    Francisco Guest

  4. #4

    Default Re: Column Number in Where Clause

    Francisco Spaeth wrote: 
    >> Not really. And this would not be good, anyway - it would be dependent
    >> on the order of the columns. Adding a column at the beginning, for
    >> instance, would break your queries.
    >>
    >> And if you're storing similar information in multiple columns, you
    >> probably need to normalize your database - which would solve your query
    >> problem.
    >>[/ref]
    >
    > Ok, I understand the situation, but I want to do a select-where
    > comparing a string with all fields in a fast way... like select * from
    > table where any_column like '%smi%'... with numbered columns that wold
    > be faster to control columns who is applied case structures or other
    > structures...
    >
    > Is any way to do this?
    >
    >[/ref]

    (Top posting fixed)

    No.

    And if your columns contain similar information, you need to normalize
    your database - which will solve your other problem.

    P.S. Please don't top post. Thanks.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  5. #5

    Default Re: Column Number in Where Clause

    On 4 Jul, 15:47, Francisco Spaeth <com> wrote: [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]



    >
    > - Show quoted text -[/ref]

    I totally agree with Jerry regarding the normalisation point.

    However it looks like you are trying to solve problems caused by poor
    data entry.

    Here are two ways to do what you are asking:

    SELECT
    CONCAT(`name`, `lastName`) `names`
    FROM `custumer`
    HAVING `names` LIKE '%smi%'

    or

    SELECT
    `name`,
    `lastName`
    FROM `custumer`
    WHERE CONCAT(`name`, `lastName`) LIKE '%smi%'


    Captain Guest

Similar Threads

  1. Replies: 0
    Last Post: February 24th, 01:06 PM
  2. use an aliased column in a WHERE clause?
    By K. in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: August 14th, 04:19 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