User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 422,920 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,334 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 727 | Replies: 4
Reply
Join Date: May 2008
Posts: 4
Reputation: stonyheng is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stonyheng stonyheng is offline Offline
Newbie Poster

Max date to max date

  #1  
May 16th, 2008
Hi all,

I wonder if it is possible that someone can drop me a code or something on this particular problem which I am currently dealing with.

in_date out_date
18/03 30/04
20/04

So how am i supposed to pair up 30/04 and 20/04 as 1 pair and show it up in the table? Many thanx in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 43
Reputation: Daedal is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 11
Daedal's Avatar
Daedal Daedal is offline Offline
Light Poster

Re: Max date to max date

  #2  
May 20th, 2008
Here is an example... could you try to be more specific?

This will select records with an in_date of '%-03-18' or out_date of '%-04-20':

SELECT * 
FROM table 
WHERE in_date LIKE '%-03-18' 
OR out_date like '%-04-20'
Reply With Quote  
Join Date: May 2008
Posts: 10
Reputation: jemajoign is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jemajoign jemajoign is offline Offline
Newbie Poster

Re: Max date to max date

  #3  
May 21st, 2008
If by 'pair up' you mean that you want them to appear in the same row, I think the approach would be to join the table to itself.

So if you had a table like:
id	description	linkid
1	item 1		3
2	item 2		1
3	item 3		2

And you want a result like:
leftdescription	rightdescription
item 2		item 1
item 3		item 2
item 1		item 3

A query like this should do it:

  1. CREATE TABLE if NOT EXISTS link2myself(id INT, description VARCHAR(6), linkid INT);
  2. INSERT INTO link2myself(id,description, linkid)
  3. SELECT 1, 'item 1', 3 UNION
  4. SELECT 2, 'item 2', 1 UNION
  5. SELECT 3,'item 3', 2;
  6.  
  7. SELECT me.description leftdescription, otherme.description rightdescription
  8. FROM link2myself me
  9. JOIN link2myself otherme on me.linkid=otherme.id;
  10.  
  11. DROP TABLE link2myself;
Reply With Quote  
Join Date: Mar 2008
Posts: 181
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Re: Max date to max date

  #4  
May 26th, 2008
Lets say you really dont want to create a table and you dont want to join tables but concatenating two records from one table instead...........

I think you need to be more specific coz what u said above is completely unclear
Last edited by Traicey : May 26th, 2008 at 11:50 am.
Reply With Quote  
Join Date: May 2008
Posts: 10
Reputation: jemajoign is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
jemajoign jemajoign is offline Offline
Newbie Poster

Re: Max date to max date

  #5  
May 26th, 2008
Just as a note, the 'CREATE TABLE' is used to create a sample table with some sample data. It has no relation to the solution. In practical usage, you would use the table you already have.

Also, if you want to string concatenate some rows you can use the aggregate function group_concat(). But if you want them to appear as separate columns, use join.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 1:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC