473,804 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem joining select strings

Joe
I've got 3 columns in a mysql database that I am trying to join. I'm using
CONCAT(), but it's giving me NULL results. This has worked for me before ...
What am I doing wrong?

Here's a straight select:

mysql> select peopleID, firstName, middleInit, lastname
-> from people;
+----------+-----------+------------+------------+
| peopleID | firstName | middleInit | lastname |
+----------+-----------+------------+------------+
| 1 | Joe | NULL | Shockey |
| 3 | John | NULL | Doe |
Here my select with the concat. It's not concatenating the string for some
reason:

mysql> select peopleID, CONCAT(firstNam e, ' ', middleInit, ' ', lastname) AS
person
-> from people;
+----------+--------+
| peopleID | person |
+----------+--------+
| 1 | NULL |
Can anyone tell me what I'm doing wrong? Should I be using a different
method for joining these srings?

BTW - here's my table structure:

mysql> show columns from people;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| peopleID | int(10) | | PRI | NULL | auto_increment |
| firstName | varchar(50) | YES | | NULL | |
| middleInit | varchar(50) | YES | | NULL | |
| lastName | varchar(50) | YES | | NULL | |
| phone | varchar(50) | YES | | NULL | |
| email | varchar(50) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+

Jul 19 '05 #1
1 4989
Joe wrote:
I've got 3 columns in a mysql database that I am trying to join. I'm using
CONCAT(), but it's giving me NULL results. This has worked for me before ...
What am I doing wrong?


CONCAT(str1,str 2,...)
Returns the string that results from concatenating the arguments.
Returns NULL if any argument is NULL. May have more than 2 arguments. A
numeric argument is converted to the equivalent string form:

mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'

CONCAT_WS(separ ator, str1, str2,...)
CONCAT_WS() stands for CONCAT With Separator and is a special form
of CONCAT(). The first argument is the separator for the rest of the
arguments. The separator can be a string as well as the rest of the
arguments. If the separator is NULL, the result will be NULL. The
function will skip any NULL values after the separator argument. The
separator will be added between the strings to be concatenated:

mysql> SELECT CONCAT_WS(","," First name","Second name","Last Name");
-> 'First name,Second name,Last Name'
mysql> SELECT CONCAT_WS(","," First name",NULL,"Las t Name");
-> 'First name,Last Name'

--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1732
by: Joe | last post by:
I've got 3 columns in a mysql database that I am trying to join. I'm using CONCAT(), but it's giving me NULL results. This has worked for me before ... What am I doing wrong? Here's a straight select: mysql> select peopleID, firstName, middleInit, lastname -> from people; +----------+-----------+------------+------------+ | peopleID | firstName | middleInit | lastname |
1
1489
by: Steve Bishop | last post by:
I have this stored proc that is to look for changes only between 2 tables and inserts the changes into one of my temp tables that I later delete in my DTS flow. I am running into a problem I think becasue in my query I am joining on fields that may not exist yet in one of the tables. Is there a way to compare the 2 tables in the query without joining them? Here is my current query:
2
3512
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2 attrdata_3 etc, etc...
3
4479
by: james | last post by:
Hi, I would like to get all the records from 9 tables that have the same field value in one field (it is a unique field)that is shared by all the tables. Would this method of joining work: select * from table 1, table 2, table 3 where table 1.com_field = table 2.com_field and table 2.com_field = table 3.com_field
2
2934
by: Shaggy Dragon | last post by:
Hi there, been looking for a solution to this for some time now. I've a UNION query that produces a table called AllSecurities: SELECT SecurityNumber, Book AS AllSecurities FROM Trades UNION SELECT SecurityNumber, Book from Positions; I'd really like to show is all the fields from the Positions table, but these don't exist in the Trades table, so they can't be included in the UNION (as far as I know). Is it possible to link this to a:
8
19604
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
1
4180
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
8
2013
by: Daz | last post by:
Hi everyone. I was faced with the choice of whether my problem is indeed a PHP problem or a MySQL. I have decided it's a PHP problem as I don't experience the same problem when I execute the same query at the CLI. I am having trouble executing a large query through my PHP script. It takes about 7-11 seconds on average to execute, whereas the same query only takes 0.01 seconds to execute through the CLI.
2
2266
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT PL_Input.Date_ID,Count(PL_Input.+PL_Input.+PL_Input.+PL_Input.+PL_Input.) AS FROM Country INNER JOIN PL_Input ON Country.Country_ID = PL_Input.Country_ID WHERE (((. & "" & . & "" & . & "" & . & "" & .) Like "*2*"))
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.