-- Database: `kanda`
-- Table structure for table `payments`
--
CREATE TABLE IF NOT EXISTS `payments` (
`paymentId` int(11) NOT NULL AUTO_INCREMENT,
`amount` double NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`paymentId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `payments`
--
INSERT INTO `payments` (`paymentId`, `amount`, `date`) VALUES
(1, 3000, '2015-01-13 08:47:46'),
(2, 3000, '2015-01-13 08:47:56');
-- phpMyAdmin SQL Dump
-- version 4.1.6
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jan 14, 2015 at 01:28 PM
-- Server version: 5.6.16
-- PHP Version: 5.5.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
--
-- Table structure for table `schools`
--
CREATE TABLE IF NOT EXISTS `schools` (
`schoolId` int(11) NOT NULL AUTO_INCREMENT,
`paymentId` int(11) NOT NULL,
`schoolname` varchar(20) NOT NULL,
PRIMARY KEY (`schoolId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Dumping data for table `schools`
--
INSERT INTO `schools` (`schoolId`, `paymentId`, `schoolname`) VALUES
(1, 1, 'westlands primary'),
(2, 2, 'st.johns primary');
答案 0 :(得分:0)
使用:
SELECT * FROM schools INNER JOIN payments ON schools.schoolname = payments.amount;
您正在尝试将学校名称与金额相匹配,这将始终失败
尝试:
SELECT schools.name, payments.amount FROM schools INNER JOIN payments ON schools.paymentId = payments.paymentId;