MySQL Forums
Forum List  »  Newbie

specific order of records in cross join
Posted by: Liviu Vasut
Date: June 11, 2010 09:00AM

Hello
I'm trying to cross join two tables and get a certain order in the returned records.
when I do
select * from a,b;
i get
+------+------+
| x    | z    |
+------+------+
|    1 | a    | 
|    2 | a    | 
|    3 | a    | 
|    1 | b    | 
|    2 | b    | 
|    3 | b    | 
|    1 | c    | 
|    2 | c    | 
|    3 | c    | 
|    1 | d    | 
|    2 | d    | 
|    3 | d    | 
+------+------+
and I'd like something like
+------+------+
| x    | z    |
+------+------+
|    1 | a    | 
|    2 | b    | 
|    3 | c    | 
|    1 | d    | 
|    2 | a    | 
|    3 | b    | 
|    1 | c    | 
|    2 | d    | 
|    3 | a    | 
|    1 | b    | 
|    2 | c    | 
|    3 | d    | 
+------+------+

I tried many variations of joins but with no luck. Documentation does not say much about order of records.
Can this be done?

Thanks

my table are:
CREATE TABLE `a` (
  `x` int(11) default NULL
);
CREATE TABLE `b` (
  `z` char(1) default NULL
);
with the data:
select * from a;
+------+
| x    |
+------+
|    1 | 
|    2 | 
|    3 | 
+------+

select * from b;
+------+
| z    |
+------+
| a    | 
| b    | 
| c    | 
| d    | 
+------+

version 5.0.77



Edited 1 time(s). Last edit at 06/11/2010 09:02AM by Liviu Vasut.

Options: ReplyQuote


Subject
Written By
Posted
specific order of records in cross join
June 11, 2010 09:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.