Forum Moderators: coopster

Message Too Old, No Replies

mySQL SELECT query question

         

lokalsound

6:22 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Hi. I am pretty new to mySQL and had a question about the SELECT statement.

Basically I have a table with say 10 fields in it. One of these fields contains a Credit Card Number and the field name is "ccn"

Instead of typing out (in PHP):

Select field1,field2,field3,field4,RIGHT(ccn,4),field6,field7 ...etc

I want to do:

Select *,RIGHT(ccn,4) from table

But the only problem is, the original ccn field (with all the numbers is still returned in the query. Is there a way to be more selective with the * query?

Basically I would like the RIGHT(ccn,4) statement to replace the full ccn field in the final output.

Thanks.

coopster

8:06 pm on Dec 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, lokalsound!

In a query such as

SELECT what_to_select
,
what_to_select
indicates what you want to see. This can be a list of columns, or * to indicate all columns. With MySQL, it's one or the other [mysql.com].

jamesa

8:50 pm on Dec 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Select *,RIGHT(ccn,4) as maskedccn from table
and in your script, call maskedccn instead of ccn.

Of course we all know not to store credit card data (unencrypted or otherwise) on a public server. Don't know whether the OP is doing this or not, but just wanted to mention it for the benefit of those who may not know. Credit card security should be taken seriously.

coopster

9:13 pm on Dec 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>But the only problem is, the original ccn field (with all the numbers is still
>>returned in the query. Is there a way to be more selective with the * query?

Just for clarification, the result set in this case is still going to contain the full ccn field along with all the other columns in the table, but now having an additional maskedccn field appended:


field1,field2,field3,field4,ccn,field6,field7...maskedccn

jamesa,

Don't know whether the OP is doing this or not

...OP...?

lokalsound

9:17 pm on Dec 16, 2003 (gmt 0)

10+ Year Member



Oh well :) I was using the RIGHT(ccn,4) as cc4 .. I just wanted to not pull back that column all together.

Thought maybe there was some undocumented (or very well hidden) mySQL function that could remove a column from the final output.

So its either SELECT *,RIGHT(ccn,4) as cc4
-or-
SELECT
one,two,three,RIGHT(ccn,4),five,six....etc

Thanks for the fast response on this.