This is a discussion on Column Number in Where Clause within the MySQL forums, part of the Database Server Software category; --> Hello, Is any way to access the column value using the number of the selected column in a select-where ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 Spaeth wrote: > 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 > 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. jstucklex@attglobal.net ================== |
| |||
| 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 <jstuck...@attglobal.net> wrote: > Francisco Spaeth wrote: > > 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 > > 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. > jstuck...@attglobal.net > ================== |
| |||
| Francisco Spaeth wrote: > On 4 jul, 10:55, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> Francisco Spaeth wrote: >>> 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 >> 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. >> > > 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? > > (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. jstucklex@attglobal.net ================== |
| ||||
| On 4 Jul, 15:47, Francisco Spaeth <francisco.spa...@gmail.com> wrote: > 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 <jstuck...@attglobal.net> wrote: > > > > > Francisco Spaeth wrote: > > > 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 > > > 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. > > jstuck...@attglobal.net > > ==================- Hide quoted text - > > - Show quoted text - 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%' |
| Thread Tools | |
| Display Modes | |
|
|