mysql Sending data slow on inner join - mysql

I have tow SAME dedicated servers.
SQL-query on first work fine and quick.
SELECT
`store_item`.`product_id`
FROM
`store_item`
INNER JOIN `store`
ON (
`store_item`.`store_id` = `store`.`id`
)
WHERE (
`store_item`.`product_id` IN (
<many id (up to 500)>
)
AND `store`.`is_active` = 1
AND `store_item`.`is_available` = 1
)
LIMIT 200 ;
On other server with SAME configuration and SAME version mysql:
What could be wrong?
update 1.
Table stucture are same in both servers.
Structure Table store
CREATE TABLE `store` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(75) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`description` longtext COLLATE utf8_unicode_ci NOT NULL,
`delivery_days` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`currency_id` int(11) NOT NULL,
`account_currency_id` int(11) NOT NULL,
`minimal_margin` decimal(5,2) NOT NULL,
`balance_money` decimal(10,2) NOT NULL,
`total_count` int(11) NOT NULL,
`added_count` int(11) NOT NULL,
`empty_count` int(11) NOT NULL,
`unknown_count` int(11) NOT NULL,
`is_distributor` tinyint(1) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`group` int(11) NOT NULL,
`sort` int(11) NOT NULL,
`return_percent` int(11) NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `store_52094d6e` (`name`),
KEY `store_41f657b3` (`currency_id`),
KEY `store_145a375d` (`sort`),
KEY `store_60ef08a5` (`account_currency_id`)
) ENGINE=MyISAM AUTO_INCREMENT=163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Structure store_item
CREATE TABLE `store_item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`store_id` int(11) NOT NULL,
`code` varchar(54) COLLATE utf8_unicode_ci NOT NULL,
`product_id` int(11) NOT NULL,
`manufacturer_id` int(11) NOT NULL,
`num` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`price_in` decimal(10,2) NOT NULL,
`price_out` decimal(10,2) NOT NULL,
`count` int(11) NOT NULL,
`is_available` tinyint(1) NOT NULL,
`delivery_days` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`discount_id` int(11) DEFAULT NULL,
`discount_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `store_id` (`store_id`,`product_id`),
KEY `store_item_47799232` (`store_id`),
KEY `store_item_44bdf3ee` (`product_id`),
KEY `store_item_516bb1bd` (`count`),
KEY `store_item_4ac7f441` (`manufacturer_id`),
KEY `store_item_3aac1984` (`num`),
KEY `store_item_52094d6e` (`name`),
KEY `store_item_5c536bf3` (`discount_id`),
KEY `store_item_65da3d2c` (`code`),
KEY `store_item_5436e97a` (`modified`),
KEY `store_item_64b158cd` (`discount_code`),
KEY `store_item_5e0d2c81` (`is_available`)
) ENGINE=MyISAM AUTO_INCREMENT=16070923 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Related

Laravel where method won't works correctly on my server but work right on my Mac

I have a weird problem, this line wont fetch any record on my server but works all right on my computer, mysql and php version are same, and when i cast id field to string it's work on server (Debian), but it is risky because i use where statement with id very much. this is the code:
$myAnswers=Questioner::where('id',$questioner_id)->first()->getLinkedAnsweres()->where("subject_id",Auth::user()->id);
and when i change it to this, it's work right (cast id to string):
$myAnswers=Questioner::where('id',$questioner_id)->first()->getLinkedAnsweres()->where("subject_id",(string)Auth::user()->id);
subject_id and user id are both unsigned_integer with same size.
How can i fix this problem? Should i overwrite where method? or is there any config which cast unsigned int to string in query?
thanks
PS: Tables structure:
users | CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`family` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`gender` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`default_password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`access_level` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'subject',
`phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`comments` longtext COLLATE utf8_unicode_ci,
`project_limit` int(10) unsigned NOT NULL,
`questioner_limit` int(10) unsigned NOT NULL,
`created_by` int(10) unsigned DEFAULT NULL,
`remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_username_unique` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
answers | CREATE TABLE `answers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`question_id` int(10) unsigned NOT NULL,
`selected_option` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`subject_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |

Mysql error 1215 - Cannot add foreign key constraint

Created these two tables successfully
First table
CREATE TABLE IF NOT EXISTS `lawncare_user` (
`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`FirstName` varchar(255) NOT NULL,
`LastName` varchar(255) NOT NULL,
`Email` varchar(255) NOT NULL,
`UserType` varchar(30) NOT NULL,
`UserName` varchar(255) NOT NULL,
`Password` varchar(255) NOT NULL,
`AddedBy` int(11) NOT NULL,
`AddedOn` date NOT NULL,
`ModifiedOn` date DEFAULT NULL,
`Status` BOOLEAN NOT NULL DEFAULT '0',
`QuestionID` int(11) DEFAULT NULL,
`QuestionAnswer` text DEFAULT NULL,
`Params` text NOT NULL,
`Address` text NOT NULL,
`Country` varchar(300) NOT NULL,
`State` varchar(300) NOT NULL,
`City` varchar(300) NOT NULL,
`ContactNo` double DEFAULT NULL,
`Activation` BOOLEAN NOT NULL DEFAULT '0',
`ActivatedOn` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Second table
CREATE TABLE IF NOT EXISTS `lawncare_customer` (
`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`FirstName` varchar(255) NOT NULL,
`LastName` varchar(255) NOT NULL,
`Email` varchar(255) NOT NULL,
`Password` varchar(255) NOT NULL,
`ContactNo` varchar(20) NOT NULL,
`Address` varchar(255) NOT NULL,
`Params` text NOT NULL,
`Province` varchar(255) NOT NULL,
`ZipCode` varchar(255) NOT NULL,
`Status` Boolean NOT NULL DEFAULT '0',
`AddedBy` int(11) NOT NULL,
`AddedOn` date NOT NULL,
`ModifiedOn` date DEFAULT NULL
) ENGINE =InnoDB DEFAULT CHARSET=latin1;
But while creating third table as
CREATE TABLE IF NOT EXISTS `lawncare_message` (
`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`Reason` int(5) NOT NULL,
`Subject` text NOT NULL,
`Description` text NOT NULL,
`Customer` int(11) NOT NULL,
`CustomerUser` varchar(255) NOT NULL,
`CustomerEmail` varchar(255) NOT NULL,
`SendTo` int(11) NOT NULL,
`SendToUser` varchar(255) NOT NULL,
`SendToEmail` varchar(255) NOT NULL,
`Status` int(5) NOT NULL DEFAULT '0',
`AddedBy` int(11) NOT NULL,
`AddedOn` date NOT NULL
FOREIGN KEY (SendTo, SendToUser, SendToEmail)
REFERENCES lawncare_user(ID, UserName, Email)
ON UPDATE CASCADE ,
FOREIGN KEY (Customer, CustomerUser, CustomerEmail)
REFERENCES lawncare_customer(ID, FirstName,Email)
ON UPDATE CASCADE
) ENGINE =InnoDB DEFAULT CHARSET=latin1
I get #1215 - Cannot add foreign key constraint , error in mysql tried adding foreign keys after creating table but it still gives the same error. I don't know what I'm doing wrong here.
First of all Check whether you have applied indexes on the keys.
As per your code their is no point in referencing id,UserName and Email.
Only id is enough for referencing.
Check the following code
CREATE TABLE IF NOT EXISTS `lawncare_message` (
`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`Reason` int(5) NOT NULL,
`Subject` text NOT NULL,
`Description` text NOT NULL,
`Customer` int(11) NOT NULL,
`CustomerUser` varchar(255) NOT NULL,
`CustomerEmail` varchar(255) NOT NULL,
`SendTo` int(11) NOT NULL,
`SendToUser` varchar(255) NOT NULL,
`SendToEmail` varchar(255) NOT NULL,
`Status` int(5) NOT NULL DEFAULT '0',
`AddedBy` int(11) NOT NULL,
`AddedOn` date NOT NULL,
FOREIGN KEY (SendTo)
REFERENCES lawncare_user(ID)
ON UPDATE CASCADE ,
FOREIGN KEY (Customer)
REFERENCES lawncare_customer(ID)
ON UPDATE CASCADE
) ENGINE =InnoDB DEFAULT CHARSET=latin1

Rails 4 Migrations from MySQL Tables

I have a pre seeded database for Countries/Regions/Cities. Is it possible to generate the migration file automatically for these tables?
CREATE TABLE IF NOT EXISTS `cities` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`country_id` int(11) unsigned NOT NULL,
`region_id` int(11) unsigned NOT NULL,
`name` varchar(255) NOT NULL,
`Latitude` float NOT NULL,
`Longitude` float NOT NULL,
`TimeZone` varchar(10) NOT NULL,
`DmaId` smallint(6) DEFAULT NULL,
`County` varchar(25) DEFAULT NULL,
`Code` varchar(4) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=42965 ;
CREATE TABLE IF NOT EXISTS `countries` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`FIPS104` varchar(2) NOT NULL,
`ISO2` varchar(2) NOT NULL,
`ISO3` varchar(3) NOT NULL,
`ISON` varchar(4) NOT NULL,
`Internet` varchar(2) NOT NULL,
`Capital` varchar(25) DEFAULT NULL,
`MapReference` varchar(50) DEFAULT NULL,
`NationalitySingular` varchar(35) DEFAULT NULL,
`NationalityPlural` varchar(35) DEFAULT NULL,
`Currency` varchar(30) DEFAULT NULL,
`CurrencyCode` varchar(3) DEFAULT NULL,
`Population` bigint(20) DEFAULT NULL,
`Title` varchar(50) DEFAULT NULL,
`Comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=276 ;
CREATE TABLE IF NOT EXISTS `regions` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`country_id` int(11) unsigned NOT NULL,
`name` varchar(255) NOT NULL,
`Code` varchar(8) NOT NULL,
`ADM1Code` char(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5400 ;
You can use
rake db:schema:dump

query with multiple joins and indexes stuck on "Copying to tmp table"

I have this query that doesn't run under odd circumstances. It's doing two joins, I have two indexes of the same name on two different tables (but this shouldn't matter). When I remove one of the indexes from either tables, the query runs fine. Something else that makes it run is removing the order by clause, but I definitely need that. When I run show processlist the state is stuck on "Copying to tmp table". The indexes I'm talking about are channelID.
the query
SELECT twitterTweets.*,
COUNT(twitterRetweets.id) AS retweets,
sTwitter.followers,
sTwitter.date
FROM twitterTweets
LEFT JOIN twitterRetweets
ON twitterTweets.id = twitterTweetsID
JOIN sTwitter
ON DATE(twitterTweets.dateCreated) = sTwitter.date
AND twitterTweets.channelID = sTwitter.channelID
WHERE twitterTweets.channelID = 32
AND type = 'tweet'
AND DATE(dateCreated) >= '2013-12-05'
AND DATE(dateCreated) <= '2014-01-05'
GROUP BY twitterTweets.id
ORDER BY dateCreated
explain results
1 SIMPLE sTwitter ref channelID channelID 5 const 1162 Using where; Using temporary; Using filesort
1 SIMPLE twitterTweets ref channelID channelID 5 const 17456 Using where
1 SIMPLE twitterRetweets ref twitterTweetsID twitterTweetsID 5 social.twitterTweets.id 3
create for the three tables
CREATE TABLE `twitterTweets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`clientID` int(11) DEFAULT NULL,
`divisionID` int(11) DEFAULT NULL,
`accountID` int(11) DEFAULT NULL,
`channelID` int(11) DEFAULT NULL,
`type` enum('tweet','reply','direct in','direct out') COLLATE utf8_unicode_ci DEFAULT 'tweet',
`subType` enum('reply beginning','retweet beginning','reply middle','retweet middle') COLLATE utf8_unicode_ci DEFAULT NULL,
`tweetID` bigint(20) DEFAULT NULL,
`tweet` text COLLATE utf8_unicode_ci,
`replies` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`hash` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`retweet` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`source` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`media` text COLLATE utf8_unicode_ci,
`tweetUrls` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`expandedUrls` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`replyToStatus` bigint(20) DEFAULT NULL,
`user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`followers` int(11) DEFAULT NULL,
`following` int(11) DEFAULT NULL,
`updates` int(11) DEFAULT NULL,
`group1` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`campaign` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`segment` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`destination` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`retweets` smallint(6) DEFAULT '0',
`favorites` smallint(6) DEFAULT NULL,
`dateCreated` datetime DEFAULT NULL,
`dateAdded` datetime DEFAULT NULL,
`dateUpdated` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `channelID` (`channelID`)
) ENGINE=MyISAM AUTO_INCREMENT=296264 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `twitterRetweets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`clientID` int(11) DEFAULT NULL,
`divisionID` int(11) DEFAULT NULL,
`accountID` int(11) DEFAULT NULL,
`channelID` int(11) DEFAULT NULL,
`twitterTweetsID` int(11) DEFAULT NULL,
`tweetID` bigint(20) DEFAULT NULL,
`screenName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`followers` int(11) DEFAULT NULL,
`following` int(11) DEFAULT NULL,
`updates` int(11) DEFAULT NULL,
`favorites` smallint(6) DEFAULT NULL,
`dateAdded` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `twitterTweetsID` (`twitterTweetsID`)
) ENGINE=MyISAM AUTO_INCREMENT=93821 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `sTwitter` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`clientID` int(11) DEFAULT NULL,
`divisionID` int(11) DEFAULT NULL,
`accountID` int(11) DEFAULT NULL,
`channelID` int(11) DEFAULT NULL,
`following` int(11) DEFAULT '0',
`followers` int(11) DEFAULT '0',
`updates` int(11) DEFAULT '0',
`date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `channelID` (`channelID`)
) ENGINE=MyISAM AUTO_INCREMENT=35615 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
So how do I make this thing run with both indexes in place? Do I have to ignore one of them?

Synchronize Table data with a whole different structure

The goal is to synchronize the customers data and his table structure to our table structure.
The table structure is the following:
CREATE TABLE IF NOT EXISTS `BildSerie_W2L` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`BildserieID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Prislista` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`BildKod` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`AvdKlassID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=24 ;
CREATE TABLE IF NOT EXISTS `classes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`client_id` int(10) unsigned NOT NULL,
`class` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`year` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `classes_client_id_foreign` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9 ;
CREATE TABLE IF NOT EXISTS `Elever_W2L` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`X_ElevID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Efternamn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Förnamn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`GataMedNr` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`PostNr` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Postort` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`TelefonMobil` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Epost1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Epost2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`X_AvdKlassId` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=18 ;
CREATE TABLE IF NOT EXISTS `Elev_Bild_BildSerie_W2L` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Elev_Bild_Bildserie_ID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`BildSerieID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`ElevID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26 ;
CREATE TABLE IF NOT EXISTS `image_codes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`client_id` int(10) unsigned DEFAULT NULL,
`code` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `image_codes_code_unique` (`code`),
KEY `image_codes_client_id_foreign` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=20 ;
CREATE TABLE IF NOT EXISTS `image_series` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`image_code_id` int(10) unsigned NOT NULL,
`pricelist_id` int(10) unsigned NOT NULL DEFAULT '1',
`class_id` int(10) unsigned DEFAULT NULL,
`image_serie` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`year` int(11) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `image_series_image_code_id_foreign` (`image_code_id`),
KEY `image_series_pricelist_id_foreign` (`pricelist_id`),
KEY `image_series_class_id_foreign` (`class_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
The goal is to take the data in "BildSerie_W2L" and populate it in to image_series.
My query looks like this:
SELECT `BildSerie_W2L`.*, `classes`.id, `image_codes`.id as ImageID, `Elever_W2L`.Förnamn, `Elever_W2L`.Efternamn
FROM `BildSerie_W2L`
INNER JOIN `image_codes` ON `BildSerie_W2L`.BildKod = `image_codes`.code
INNER JOIN `classes` ON `BildSerie_W2L`.AvdKlassID = `classes`.class
INNER JOIN `Elev_Bild_BildSerie_W2L` ON `Elev_Bild_BildSerie_W2L`.BildSerieID = `BildSerie_W2L`.BildserieID
INNER JOIN `Elever_W2L` ON `Elever_W2L`.X_ElevID = `Elev_Bild_BildSerie_W2L`.ElevID
WHERE `BildSerie_W2L`.Status = 0
However it gives back duplicated results and not all the data in BildSerie_W2L...