Unix Technical Forum

Column Number in Where Clause

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:10 AM
Francisco Spaeth
 
Posts: n/a
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:10 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Column Number in Where Clause

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:10 AM
Francisco Spaeth
 
Posts: n/a
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 <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
> ==================



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:10 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Column Number in Where Clause

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:10 AM
Captain Paralytic
 
Posts: n/a
Default Re: Column Number in Where Clause

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%'


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com