473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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,prevowner etc etc etc...

Table 2 (property_imagelist) - 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_imagelist` ON (`property_inventory`.`pcode` =
`vehicle_imagelist`.`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_inventory 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,11112tmb.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 4764
Andrew wrote:
From a data export requirement, what I ideally need is all the fields
from the property_inventory 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,11112tmb.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_inventory AS P
LEFT OUTER JOIN property_imagelist AS I1
ON P.PCODE = I1.PCODE
LEFT OUTER JOIN property_imagelist AS I2
ON P.PCODE = I2.PCODE AND I1.IMAGE < I2.IMAGE
LEFT OUTER JOIN property_imagelist 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
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
8
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. ...
0
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 >...
4
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...
2
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...
6
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...
3
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...
2
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.