Jump to content

Complex selection using SQL


mindsoul

Recommended Posts

Complex selection using SQL only.

so i have the table as view in the attach file.

i want to select all the rows where term_lang=1 and don't have a corispondent(translation in my case) in the term_lang=2.

Praticly i want to select the terms in one particular language that are not yet translated in another.

this is the code, table

-- Version MySQL: 5.0.24

CREATE TABLE IF NOT EXISTS `terms` (
  `term_id` int(10) unsigned NOT NULL auto_increment,
  `term_category` tinyint(3) NOT NULL,
  `term_name` varchar(250) NOT NULL,
  `term_lang` int(2) NOT NULL,
  `term_relation_field` int(10) NOT NULL,
  PRIMARY KEY  (`term_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=34 ;



INSERT INTO `terms` (`term_id`, `term_category`, `term_name`, `term_lang`, `term_relation_field`) VALUES
(1, 1, 'Caviale', 1, 1),
(2, 1, 'Insalata di mare', 1, 2),
(3, 6, 'Arrosto di maiale', 1, 3),
(6, 1, 'Seafood salat', 2, 2),
(7, 6, 'Cerdo asado', 4, 3),
(8, 1, 'Ensalada de mariscos', 4, 1),
(9, 1, 'Kaviar', 5, 1),
(28, 6, 'Cervella alla milanese', 1, 6),
(11, 1, 'kèviar', 8, 1),
(12, 1, 'caviale espaniol', 4, 1),
(13, 1, 'caviale fracais 2', 3, 1),
(14, 1, 'salade du mèr', 3, 2),
(15, 6, 'porc la gratar', 9, 3),
(19, 6, 'porc la gratar', 9, 3),
(20, 6, 'porca la gratar2', 9, 3),
(21, 6, 'le porc du france international', 3, 3),
(22, 1, 'икра', 7, 1),
(23, 1, 'Салат море', 7, 2),
(24, 1, 'meeresfrüchten salat', 5, 2),
(25, 6, 'Жаркое из свинины', 7, 3),
(26, 9, 'bresaola della valtelina', 1, 4),
(27, 9, 'salame di cinghiale', 1, 5),
(29, 6, 'Creier alla Milanese', 9, 6),
(30, 6, 'Cinghiale', 1, 7),
(31, 6, 'Porc mistret', 9, 7),
(32, 7, 'Astice', 1, ,
(33, 7, 'Crevete', 9, ;

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

i don't know how to do this using only sql, i have the solution using php, but the problem come's out when i work in php with big arrays, because i must select all the terms in one language then in the other language, compare and show the terms that must be translated (that are not yet translated), so when you work with multidimensional array with thousend of rows is not so big perfomance, that's why i must know if is possibile to do such a selection using SELECT and subqueries with wich i don't have a background.

Link to comment
Share on other sites

i think i have it

 SELECT* FROM terms WHERE  
	term_relation_field NOT IN (SELECT DISTINCT term_relation_field FROM terms WHERE term_lang=9) AND term_lang=1; 

very difficult all this nested select but helpful, I'll see the performance with thousand of rows

Link to comment
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.