473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two table concatenate issue?

Hello,

Rather complicated one im afraid.. (well for me anyway!) Background on
this one is that I have inherited a system that needs some
modification, have some basic sql knowledge but fear i've bitten off a
little bit more than I can handle.

I need to export some data which I am able to do as I have some
exporting software which can just tap into a mysql database. Its a
fairly straightforward real estate database.

Table 1 (property_info) - pcode, name,add1,prevo wner etc etc etc...

Table 2 (property_image list) - pcode, thumbnail, image

This database basically runs the backend part of a search/add php
system..the usual stuff.

Thing is I need to export the data into a specific comma delimited
format..which I can do fine very easily with MySQL Data Wizard
(http://www.sqlmaestro.com/products/mywizard)..thing is the format
that I need the csv needs to have all the info from the propery_info
table, but also the image filenames stored in the image field in the
property_images table.

Still with me? Hope so! So within the MySQL data wizard app I can
write an SQL query off the database which it then can then create an
csv file..perfect. Well so I thought until I tried to do it.

I can merge the two tables together very simply. just using

INNER JOIN `property_image list` ON (`property_inve ntory`.`pcode` =
`vehicle_imagel ist`.`pcode`)

This is perfect, all but one snag and this is where Im hoping someone
here can help. Within the imagelist table there are multiple images.
So for example :-

PCODE THUMBNAIL IMAGE
1534 8888tmb.jpg 8888.jpg
3244 1111tmb.jpg 1111.jpg
3244 11112tmb.jpg 11112.jpg
3244 11113tmb.jpg 11114.jpg
5335 1112tmb.jpg 1112.jpg
Ok, so we got multiple images for some (3244) but not for others
(another problem) indeed some of them only have one pic (1534 and
5355)..

From a data export requirement, what I ideally need is all the fields
from the property_invent ory table PLUS (hopefully sql is able to do
this) a concatenated or generated IMAGES field (apologies don't know
the correct term) like this :-

PCODE IMAGES

1534 8888.jpg
3244 1111.jpg,11112t mb.jpg,11113tmb .jpg
5335 1112.jpg

NOTICE that its just the first image filename and then whatever
thumbnail filenames exist. This will then give me a perfect export for
my needs.

Any help on this would be absolutely amazing! Thanks in advance for
anyone who is kind enough to look at this.

Regards,

A West
Jul 23 '05 #1
1 4796
Andrew wrote:
From a data export requirement, what I ideally need is all the fields
from the property_invent ory table PLUS (hopefully sql is able to do
this) a concatenated or generated IMAGES field (apologies don't know
the correct term) like this :-

PCODE IMAGES

1534 8888.jpg
3244 1111.jpg,11112t mb.jpg,11113tmb .jpg
5335 1112.jpg


I don't believe this can be done in the general case (i.e. an unknown
number of images for a given pcode) in a single SQL statement, without
using a stored procedure or user-defined function.

I think you could do it using outer joins, if you could assume a finite
limit to the number of images per pcode, but this isn't a general
solution. For instance, here's a solution for up to three images per pcode:

SELECT P.PCODE,
CONCAT_WS(',', I1.IMAGE, I2.IMAGE, I3.IMAGE) AS IMAGES
FROM property_invent ory AS P
LEFT OUTER JOIN property_imagel ist AS I1
ON P.PCODE = I1.PCODE
LEFT OUTER JOIN property_imagel ist AS I2
ON P.PCODE = I2.PCODE AND I1.IMAGE < I2.IMAGE
LEFT OUTER JOIN property_imagel ist AS I3
ON P.PCODE = I3.PCODE AND I2.IMAGE < I3.IMAGE;

(caveat: I have not tested this query)

CONCAT_WS() is a MySQL function that concatenates its arguments
together, separated by the first argument (',' in this case), and it
skips any NULL arguments.
See http://dev.mysql.com/doc/mysql/en/string-functions.html.

Regards,
Bill K.
Jul 23 '05 #2

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

Similar topics

30
27049
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
8
11134
by: Sharknwfk | last post by:
Hi, Hoping someone can help. I am trying to concatenate the ages of still living children divided into male & female. So, male 23, female 25, male 13, female 18 should look like this. Female: 25, 18
0
1307
by: Sharknwfk | last post by:
"Sharknwfk" <sharknwfk@co.nz.uk> wrote in message news:41bc8f61@clear.net.nz... > > "Chuck Grimsby" <c.grimsby@worldnet.att.net.invalid> wrote in message > news:aq9or0pj8i5t83us5ic2004km12g81fbdi@4ax.com... > > On Sun, 12 Dec 2004 14:16:57 +1300, "Sharknwfk" <sharknwfk@co.nz.uk> > > wrote: > > >"Chuck Grimsby" <c.grimsby@worldnet.att.net.invalid> wrote in message > > >news:ubklr09i25nc2o1fm09svu0oa6e7h0hj93@4ax.com... > > >> Do a...
4
2353
by: Onion | last post by:
This has to be simple, but I'm forced to admit that I'm a novice who can't figure it out. I have a listbox in a form that allows multiple selections. That works fine. The problem: I can't figure out how to store the data. I want to store the items chosen from the listbox in a field for the current record. That means the table field must store the variable number of text items selected from the listbox by the user.
2
6790
by: Kevin | last post by:
Hello, How do I concatenate two fields in the same table... For example, I have two tables, first one is called familynametable that has a familyID and familyname field. This table is connected to a individualnametable that contains three fields: individualnameID, FamilyID (to link to familytable) and FirstName. In the familytable, FamilyID=1, FamilyName=Doe, In the individualtable there are two records:
6
4309
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by concatenating them at the bottom and then concatenating them side by side: for ind in range(num_arrays): if ind == 0: bias_down1 = array(bias)
3
1927
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but enough to get the idea). Here is the code: ----------------------------------------------------------------- <html>
2
6679
by: exapplerep | last post by:
I've seen how to use VBA code to concatenate two fields into a third by using an expression in the "After Update" property in fields 1 & 2. field3 = field1 + field2 The above code would go into both fields 1 and 2. Here's the problem: It is possible that field1 may be blank (or may be made empty by the user). In this case, tabbing out of field1 (after emptying it, for example) also empties field3. Now tabbing out of
6
26852
by: antmail | last post by:
Hi guys, I have spend several days now trying to solve this problem inside a stored procedure. I want to call a procedure providing 3 variables. The variables area used to select the appropriate table from within the database. I have to concatenate the 3 variables to make up the whole table name and concatenate that with the field name. The hard coded procedures looks as follows: DROP PROCEDURE IF EXISTS...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9737
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...
1
7286
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
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
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
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.