When I concat($name, $surname), is there a way of putting a space in between the $name $surname using my sql not php so when i get the result it formats a little cleaner?
You can concatenate string literals along with your fields, so you can add a space character in a string between the fields you're concatenating.
Use this:
CONCAT(name, " ", surname)
This functionality is documented quite clearly on the MySQL manual page for the CONCAT() function.
There is also the CONCAT_WS function which allows you to specify a separator to be used between each of the other fields passed to the function. If you're concatenating more than two fields in the same way, this function might be considered cleaner than repeating the separator between each field.
For example, if you wanted to add a middle name field, you could use this function to specify the separator only once:
CONCAT_WS(" ", first_name, middle_name, surname)
Just add a space in there.
SELECT CONCAT(name,' ',surname) AS full_name FROM table;
EDIT oops, bad spelling there... ;p
Use this, no version dependencies
concat(name,Char(32),venue)
Use CONCAT(name, ' ', surname).
after trying this i tried to do this
concat(name, _utf8 ' ' ,name1)
Hey i had the same problem and this is what i used and it really worked out great
CONCAT(column1," ",column2)
the issue is you add physical space in between the double courts("") using the space bar on your keyboard and then thats it
The above all options are not working ..
My query is
SELECT CONCAT(FIRSTNAME, ' ' , LASTNAME) AS FULLNAME FROM USERS;
getting the below error:
ORA-00909: invalid number of arguments 00909 00000- "invalid number of arguments" *Cause: *Action: Error at line 26 column :9
Use this methoid to add separator
CONCAT_WS(' ', first_string, second_string, n_string, ..., last_string)
Related
I'm trying to remove parenthesis from the area code of a number. I'm able to do so but when I try to concatenate the two Replace functions, the numbers repeat with only one parenthesis removed.
This is what I tried so far:
SELECT HomePhone, REPLACE(HomePhone, '(', '') +
REPLACE(HomePhone, ')', '') AS Expr1
FROM dbo.Employees
http://i.imgur.com/4iJoFzE.png
Nest don't add
Replace(Replace(HomePhone,')',''),'(','')
Look at how the function replace works. It expects string With Text To Evaluate, string to replace, string to replace with)
By adding them you should be getting the number listed twice, but if the data type isn't long enough it may be truncating values. by nesting you're telling the system to replace the ) and then use that string w/o the ) to have the ( replaced with ''.
You cannot concatenate in this way, you must use the concat function in SQL. Or use thus:
SELECT HomePhone, REPLACE(REPLACE(HomePhone, ')', ''), '(', '') AS Expr1 FROM dbo.Employees
I'm using Wordpress and have a load of custom fields where I need to do a string replace on. Basically I have a price field which is in the example format:
from 113.800
I need to remove the word 'from', the space after it and the dot between the number. All the fields are in this format, how can I use a MySQL replace function to do this?
Thanks
REPLACE() doesn't support regular expression matching, so you'll have to do it in a more clumsy way:
UPDATE wp_sometable
SET price_field = REPLACE(REPLACE(price_field, 'from ', ''), '.', '');
I am trying to display one column name with '%' i.e the "ip_utilization" column as "usage%" column here. But i am not able to, can anyone suggest a solution please. I am sharing the query.
select ip_name, concat (first_name, ' ' ,last_name) as Contact, ip_utilization as usage_% from database_name;
Just give it a different column name? Like usage_percentage.
It may be possible to have the percent sign using backticks, but to what end? What point is there in jumping through hoops to somehow have a weird special character in a name that usually won't be displayed in an application anyway?*
(Unless it's really a public-facing app and you can't change the name on application level at all. But that should be the rare exception.)
Enclose usage_% in `` as below:
select ip_name, concat (first_name, ' ' ,last_name) as Contact, ip_utilization as `usage_%` from database_name;
If you have further problems, leave a comment.
You should be able to use backticks
select ip_name, concat (first_name, ' ' ,last_name) as Contact, ip_utilization as `usage_%` from database_name;
Quote usage%. But I advice to change the name, because % is keyword used for like command.
select ip_name, concat (first_name, ' ' ,last_name) as Contact,
ip_utilization as 'usage_%' from database_name;
I have a query where I am using GROUP_CONCAT and a custom separator as my results may contain commas: '----'
This all works well, however it is still comma separated, so my output is:
Result A----,Result B----,Result C----
How can I make it so the output is:
Result A----Result B----Result C----
I thought this was the idea of a custom separator!
Failing that, can you escape commas in your results, so I can explode in PHP by the GROUP_CONCAT commas?
Looks like you're missing the SEPARATOR keyword in the GROUP_CONCAT function.
GROUP_CONCAT(artists.artistname SEPARATOR '----')
The way you've written it, you're concatenating artists.artistname with the '----' string using the default comma separator.
Query to achieve your requirment
SELECT id,GROUP_CONCAT(text SEPARATOR ' ') AS text FROM table_name group by id;
Or, if you are doing a split - join:
GROUP_CONCAT(split(thing, " "), '----') AS thing_name,
You may want to inclue WITHIN RECORD, like this:
GROUP_CONCAT(split(thing, " "), '----') WITHIN RECORD AS thing_name,
from BigQuery API page
I'm not exactly sure what happened because I migrated from One server to another of the same spec and SQL...
Still in comments and titles the new database shows the characters ' instead of '
and I was wondering if I could ask for help in either replacing ' with '
or if it was simpler just deleting '
Thanks so much...
Steff
You could use MySQL's REPLACE method (look here):
UPDATE
Changed the statement to reflect the OP's naming:
UPDATE database1.vb_ppgal_albums
SET pp_photos = REPLACE(pp_photos, ''', '\'')
Good luck.
The following is the coding that I use to update double-quote in MySQL. I use the REPLACE function. The first parameter is the field_name that I want to have searched, the second is the escaping of the double quote (\") as the search string, followed by escaping of the escape character (\) followed by the double quote, which will insert into the field name (\"). In the table I will now have a measurement of '1/2\"' instead of '1/2"', which was my goal. I hope this helps. (PS, the Where clause is for show, you may not need it.)
UPDATE `table_name`
SET
`field_name` = REPLACE(`field_name`, '\"', '\\"')
WHERE `Id` > 125