Jump to content

A query within one query


AndyPSV

Recommended Posts

I've got a table.

 

id group cid u date id_

7 1 answer_comment 6 2012-01-14 18:13:27 9#8

2 1 question_comment 5 2012-01-14 16:01:40 9

3 1 question_follow 5 2012-01-14 16:01:40 9

4 0 answer_anyoneVote 5 2012-01-14 16:01:40 11

5 0 question_follow 5 2012-01-14 16:01:40 8

6 1 question_follow 5 2012-01-14 16:01:40 21

 

& I've got a mysql_query, e.g.:

 

SELECT * FROM xernt_mailing WHERE date <= "2012-01-14 19:32:17" AND `group` = "1" AND u = "6" ORDER BY cid DESC

 

____ What I want to do, is to select ORDER of "cid" FROM ANOTHER TABLE, preferable: ___

 

 

CREATE TABLE `xernt_cid_seq` (

  `cid` varchar(255) NOT NULL,

  `seq` int(11) NOT NULL,

  KEY `cid` (`cid`,`seq`)

) ENGINE=MyISAM DEFAULT CHARSET=latin2;

 

--

-- Dumping data for table `xernt_cid_seq`

--

 

INSERT INTO `xernt_cid_seq` (`cid`, `seq`) VALUES

('question_answer', 10),

('question_editDescr', 200),

('question_editT', 100);

 

 

------------- (preview)

cid seq

question_answer 10

question_editDescr 200

question_editT 100

 

 

--------------------------------------------------------------------------------

 

I was combining with:

 

SELECT * FROM xernt_mailing WHERE date <= "2012-01-14 19:32:17" AND `group` = "1" AND u = "6" ORDER BY (SELECT cid FROM xernt_cid_seq WHERE cid = '...... ? ORDER BY seq DESC) DESC

 

but need to figure how do it: could anyone help?

 

 

 

----

didn't added first table:

 

 

 

CREATE TABLE `xernt_mailing` (

`id` bigint(20) NOT NULL auto_increment,

`group` tinyint(4) NOT NULL,

`cid` varchar(255) NOT NULL,

`u` int(11) NOT NULL,

`date` datetime NOT NULL,

`id_` varchar(255) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=8 ;

 

--

-- Dumping data for table `xernt_mailing`

--

 

INSERT INTO `xernt_mailing` (`id`, `group`, `cid`, `u`, `date`, `id_`) VALUES

(7, 1, 'answer_comment', 6, '2012-01-14 18:13:27', '9#8'),

(2, 1, 'question_comment', 5, '2012-01-14 16:01:40', '9'),

(3, 1, 'question_follow', 5, '2012-01-14 16:01:40', '9'),

(4, 0, 'answer_anyoneVote', 5, '2012-01-14 16:01:40', '11'),

(5, 0, 'question_follow', 5, '2012-01-14 16:01:40', '8'),

(6, 1, 'question_follow', 5, '2012-01-14 16:01:40', '21');

 

 

maybe making it more clear: so the "cid" would be selected by the order of sequence that is attached to their name (as selected from another table)

Link to comment
https://forums.phpfreaks.com/topic/255019-a-query-within-one-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.