Jump to content

Recommended Posts

MySQL client version: 4.1.22 - Server version: 4.0.25-standard - phpMyAdmin - 2.10.0.2 (it's what they provide).

 

My table was originally defined thus:-

 

CREATE TABLE `triviadata` (

  `id` int(11) NOT NULL auto_increment,

  `date` varchar(8) NOT NULL default '',

  `year` varchar(8) NOT NULL default '',

  `data` text NOT NULL,

  PRIMARY KEY  (`id`)

) TYPE=InnoDB ;

 

 

date contains the day/month part of the date i.e. 18 Apr, year contains a four digit number i.e. 1969.

 

 

I want to join two fields together from my database into a new field on a search query, namely date and year fields. I have tried searching on the 'net for a solution  but all I can find is ways of joining tables. I can do that, but cannot get two fields to join. My attempts give results which are not really what I require.

 

SELECT id, date & ' ' & year AS newdate, data

FROM `triviadata`

WHERE `year` LIKE '%1969%'

LIMIT 0 , 30

 

it outputs the id, and data fields ok, but the newdate field is a 'zero'. I figure it is ANDing them together maybe?

 

SELECT id, date + ' ' + year AS newdate, data

FROM `triviadata`

WHERE `year` LIKE '%1969%'

LIMIT 0 , 30

 

this doesn't work either. All I get is the year field with a nuber from the date field added to it.

 

SELECT id, date || ' ' || year AS newdate,

DATA

FROM `triviadata`

WHERE `year` LIKE '%1969%'

LIMIT 0 , 30

 

this doesn't work, all I get is the newdate field equal to '1' for all occurences of 1969 that are found.

 

 

I know I probably should have used a proper date field, but it can't cope with dates prior to year 1000 and my trivia database has many entries for years prior to this, including BC years.

 

 

So how do I do it?  I can't write my php till I know how.

 

 

 

Suzanne.

Link to comment
https://forums.phpfreaks.com/topic/83654-solved-joining-two-fields/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.