100% found this document useful (1 vote)
29 views

Get Getting Started with SQL and Databases: Managing and Manipulating Data with SQL 1st Edition Mark Simon free all chapters

Mark

Uploaded by

clalupromet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
29 views

Get Getting Started with SQL and Databases: Managing and Manipulating Data with SQL 1st Edition Mark Simon free all chapters

Mark

Uploaded by

clalupromet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Experience Seamless Full Ebook Downloads for Every Genre at ebookmeta.

com

Getting Started with SQL and Databases: Managing


and Manipulating Data with SQL 1st Edition Mark
Simon

https://ebookmeta.com/product/getting-started-with-sql-and-
databases-managing-and-manipulating-data-with-sql-1st-
edition-mark-simon/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

SQL QuickStart Guide The Simplified Beginner s Guide to


Managing Analyzing and Manipulating Data With SQL Walter
Shields
https://ebookmeta.com/product/sql-quickstart-guide-the-simplified-
beginner-s-guide-to-managing-analyzing-and-manipulating-data-with-sql-
walter-shields/
ebookmeta.com

Python Data Persistence With SQL and NOSQL Databases 1st


Edition Lathkar

https://ebookmeta.com/product/python-data-persistence-with-sql-and-
nosql-databases-1st-edition-lathkar/

ebookmeta.com

Leveling Up with SQL: Advanced Techniques for Transforming


Data into Insights 1st Edition Mark Simon

https://ebookmeta.com/product/leveling-up-with-sql-advanced-
techniques-for-transforming-data-into-insights-1st-edition-mark-simon/

ebookmeta.com

Asian Development Bank Sustainability Report 2018


Investing for an Asia and the Pacific Free of Poverty 1st
Edition Asian Development Bank
https://ebookmeta.com/product/asian-development-bank-sustainability-
report-2018-investing-for-an-asia-and-the-pacific-free-of-poverty-1st-
edition-asian-development-bank/
ebookmeta.com
Friends with Benefits Goals Friends To Lovers Bad Boy
Sports Romance Romance Goals Book 4 1st Edition Barbi Cox

https://ebookmeta.com/product/friends-with-benefits-goals-friends-to-
lovers-bad-boy-sports-romance-romance-goals-book-4-1st-edition-barbi-
cox/
ebookmeta.com

Philosophical Trends in the Feminist Movement 2nd Edition


Anuradha Ghandy

https://ebookmeta.com/product/philosophical-trends-in-the-feminist-
movement-2nd-edition-anuradha-ghandy/

ebookmeta.com

The Appraisal of Real Estate 15th Edition Appraisal


Institute

https://ebookmeta.com/product/the-appraisal-of-real-estate-15th-
edition-appraisal-institute/

ebookmeta.com

THE WATCHER I spy with my little eye someone is going to


die 1st Edition Lisa Sell

https://ebookmeta.com/product/the-watcher-i-spy-with-my-little-eye-
someone-is-going-to-die-1st-edition-lisa-sell/

ebookmeta.com

Handbook of Epigenetics : The New Molecular and Medical


Genetics 3rd Edition Trygve O. Tollefsbol

https://ebookmeta.com/product/handbook-of-epigenetics-the-new-
molecular-and-medical-genetics-3rd-edition-trygve-o-tollefsbol/

ebookmeta.com
Management 12th Edition Ricky W. Griffin

https://ebookmeta.com/product/management-12th-edition-ricky-w-griffin/

ebookmeta.com
Getting Started
with SQL and
Databases
Managing and Manipulating Data
with SQL

Mark Simon
Getting Started with
SQL and Databases
Managing and Manipulating Data
with SQL

Mark Simon
Getting Started with SQL and Databases: Managing and Manipulating Data
with SQL

Mark Simon
Ivanhoe VIC, VIC, Australia

ISBN-13 (pbk): 978-1-4842-9492-5 ISBN-13 (electronic): 978-1-4842-9493-2


https://doi.org/10.1007/978-1-4842-9493-2
Copyright © 2023 by Mark Simon
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Smriti Srivastava
Development Editor: Laura Berendson
Editorial Assistant: Mark Powers
Cover image designed by eStudioCalamar
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub. For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To Sachiko. Thanks for your patience, forbearance, and trust.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Starting with SQL������������������������������������������������������������������������������������ 1


Basic SELECT Statement��������������������������������������������������������������������������������������������������������������� 2
Case Sensitivity����������������������������������������������������������������������������������������������������������������������� 3
Spacing������������������������������������������������������������������������������������������������������������������������������������ 3
Clause Ordering����������������������������������������������������������������������������������������������������������������������� 4
The Semicolon (;)��������������������������������������������������������������������������������������������������������������������� 4
Selecting Specific Columns���������������������������������������������������������������������������������������������������������� 5
Column Order�������������������������������������������������������������������������������������������������������������������������� 6
Layout�������������������������������������������������������������������������������������������������������������������������������������� 6
Using SELECT *������������������������������������������������������������������������������������������������������������������������ 7
Calculated Columns����������������������������������������������������������������������������������������������������������������� 7
Aliases������������������������������������������������������������������������������������������������������������������������������������� 8
Comments������������������������������������������������������������������������������������������������������������������������������������� 9
Block Comments������������������������������������������������������������������������������������������������������������������� 10
Uses of Comments���������������������������������������������������������������������������������������������������������������� 10
Filtering Rows����������������������������������������������������������������������������������������������������������������������������� 11
Clause Ordering��������������������������������������������������������������������������������������������������������������������� 12
Placing the Semicolon����������������������������������������������������������������������������������������������������������� 13
Ordering the Results������������������������������������������������������������������������������������������������������������������� 13
Clause Order�������������������������������������������������������������������������������������������������������������������������� 14
Distinct Rows������������������������������������������������������������������������������������������������������������������������������ 15

v
Table of Contents

Summary������������������������������������������������������������������������������������������������������������������������������������ 18
Writing SQL���������������������������������������������������������������������������������������������������������������������������� 19
Columns��������������������������������������������������������������������������������������������������������������������������������� 20
Comments����������������������������������������������������������������������������������������������������������������������������� 20
Filtering Data������������������������������������������������������������������������������������������������������������������������� 20
Row Order������������������������������������������������������������������������������������������������������������������������������ 21
Clause Order�������������������������������������������������������������������������������������������������������������������������� 21
Coming Up����������������������������������������������������������������������������������������������������������������������������������� 21

Chapter 2: Database����������������������������������������������������������������������������������������������� 23
About the Sample Database�������������������������������������������������������������������������������������������������������� 23
Database������������������������������������������������������������������������������������������������������������������������������� 24
Tables������������������������������������������������������������������������������������������������������������������������������������ 26
Normalized Tables����������������������������������������������������������������������������������������������������������������� 27
Multiple Values���������������������������������������������������������������������������������������������������������������������� 33
Summary������������������������������������������������������������������������������������������������������������������������������� 37
Coming Up����������������������������������������������������������������������������������������������������������������������������� 39

Chapter 3: Filtering Data���������������������������������������������������������������������������������������� 41


The WHERE Clause���������������������������������������������������������������������������������������������������������������������� 41
Unrelated Assertions������������������������������������������������������������������������������������������������������������� 44
All and Nothing���������������������������������������������������������������������������������������������������������������������� 44
Dealing with NULL����������������������������������������������������������������������������������������������������������������������� 45
Deliberately Ignoring NULLs�������������������������������������������������������������������������������������������������� 46
Finding NULLs������������������������������������������������������������������������������������������������������������������������ 47
Numbers������������������������������������������������������������������������������������������������������������������������������������� 49
Discrete vs. Continuous Values��������������������������������������������������������������������������������������������� 49
Strings����������������������������������������������������������������������������������������������������������������������������������������� 52
Quotes����������������������������������������������������������������������������������������������������������������������������������� 53
More on MySQL/MariaDB Modes������������������������������������������������������������������������������������������� 54
More on Double and Single Quotes��������������������������������������������������������������������������������������� 55
Case Sensitivity��������������������������������������������������������������������������������������������������������������������� 57
Trailing Spaces���������������������������������������������������������������������������������������������������������������������� 58

vi
Table of Contents

Filtering with String Functions���������������������������������������������������������������������������������������������� 59


Handling Quotes and Apostrophes���������������������������������������������������������������������������������������� 61
Before and After Strings�������������������������������������������������������������������������������������������������������� 62
Dates������������������������������������������������������������������������������������������������������������������������������������������� 63
Dates Are Not Strings������������������������������������������������������������������������������������������������������������ 64
Alternative Date Formats������������������������������������������������������������������������������������������������������� 65
Date Comparisons����������������������������������������������������������������������������������������������������������������� 66
Filtering with a Date Calculation������������������������������������������������������������������������������������������� 69
Multiple Assertions��������������������������������������������������������������������������������������������������������������������� 70
AND and OR��������������������������������������������������������������������������������������������������������������������������� 70
The IN Operator��������������������������������������������������������������������������������������������������������������������� 76
Derived Lists�������������������������������������������������������������������������������������������������������������������������� 78
Wildcard Matches����������������������������������������������������������������������������������������������������������������������� 81
Case Sensitivity and Patterns������������������������������������������������������������������������������������������������ 83
Pattern Characters���������������������������������������������������������������������������������������������������������������� 84
Wildcards with Non-strings��������������������������������������������������������������������������������������������������� 87
Extensions to Wildcards�������������������������������������������������������������������������������������������������������� 89
A Simple Pattern Match Example������������������������������������������������������������������������������������������ 91
Summary������������������������������������������������������������������������������������������������������������������������������������ 92
NULL�������������������������������������������������������������������������������������������������������������������������������������� 93
Numbers�������������������������������������������������������������������������������������������������������������������������������� 93
Strings����������������������������������������������������������������������������������������������������������������������������������� 93
Dates������������������������������������������������������������������������������������������������������������������������������������� 94
Multiple Assertions���������������������������������������������������������������������������������������������������������������� 94
The IN Operator��������������������������������������������������������������������������������������������������������������������� 94
Wildcard Matches������������������������������������������������������������������������������������������������������������������ 94
Coming Up����������������������������������������������������������������������������������������������������������������������������������� 95

Chapter 4: Ordering Results����������������������������������������������������������������������������������� 97


Using the ORDER BY Clause�������������������������������������������������������������������������������������������������������� 97
Sort Direction������������������������������������������������������������������������������������������������������������������������� 99
Missing Data (NULL)������������������������������������������������������������������������������������������������������������������ 100

vii
Table of Contents

Data Types��������������������������������������������������������������������������������������������������������������������������������� 102


Case Sensitivity and Collation��������������������������������������������������������������������������������������������� 106
Multiple Columns���������������������������������������������������������������������������������������������������������������������� 107
Interdependence of Columns����������������������������������������������������������������������������������������������� 109
Sort Direction on Multiple Columns������������������������������������������������������������������������������������� 110
Sorting by Calculated Columns������������������������������������������������������������������������������������������������� 112
Limiting the Number of Results������������������������������������������������������������������������������������������������ 115
Paging��������������������������������������������������������������������������������������������������������������������������������� 116
Using LIMIT … OFFSET … (MySQL/MariaDB, SQLite, and PostgreSQL)������������������������������ 117
Using TOP (MSSQL)�������������������������������������������������������������������������������������������������������������� 117
Fetching a Random Row����������������������������������������������������������������������������������������������������������� 118
Nonalphabetical String Order���������������������������������������������������������������������������������������������������� 119
Special Strings�������������������������������������������������������������������������������������������������������������������������� 120
Summary���������������������������������������������������������������������������������������������������������������������������������� 121
Sorting with ORDER BY�������������������������������������������������������������������������������������������������������� 121
Limiting Results������������������������������������������������������������������������������������������������������������������� 122
Sorting Strings��������������������������������������������������������������������������������������������������������������������� 122
Coming Up��������������������������������������������������������������������������������������������������������������������������������� 122

Chapter 5: Calculating Column Values������������������������������������������������������������������ 123


Testing Calculations������������������������������������������������������������������������������������������������������������������ 125
Emulating Variables������������������������������������������������������������������������������������������������������������������ 126
Some Basic Calculations����������������������������������������������������������������������������������������������������������� 127
Basic Number Calculations������������������������������������������������������������������������������������������������� 127
Basic String Calculations����������������������������������������������������������������������������������������������������� 128
Basic Date Calculations������������������������������������������������������������������������������������������������������� 129
Working with NULL�������������������������������������������������������������������������������������������������������������������� 129
Using Aliases����������������������������������������������������������������������������������������������������������������������������� 135
Aliases Without AS��������������������������������������������������������������������������������������������������������������� 136
Awkward Aliases����������������������������������������������������������������������������������������������������������������� 138
Calculating with Numbers��������������������������������������������������������������������������������������������������������� 140

viii
Table of Contents

Arithmetic Operators����������������������������������������������������������������������������������������������������������� 140


Integers������������������������������������������������������������������������������������������������������������������������������� 141
Remainder��������������������������������������������������������������������������������������������������������������������������� 143
Extra Decimals��������������������������������������������������������������������������������������������������������������������� 144
Mathematical Functions������������������������������������������������������������������������������������������������������ 145
Approximation Functions����������������������������������������������������������������������������������������������������� 146
Formatting Functions���������������������������������������������������������������������������������������������������������� 147
Calculating with Dates�������������������������������������������������������������������������������������������������������������� 149
Simple Calculations������������������������������������������������������������������������������������������������������������� 149
Age Calculations������������������������������������������������������������������������������������������������������������������ 151
Extracting Parts of a Date���������������������������������������������������������������������������������������������������� 153
Formatting a Date���������������������������������������������������������������������������������������������������������������� 155
Strings��������������������������������������������������������������������������������������������������������������������������������������� 160
Character Functions������������������������������������������������������������������������������������������������������������ 161
Subqueries�������������������������������������������������������������������������������������������������������������������������������� 165
The CASE Expression���������������������������������������������������������������������������������������������������������������� 169
Casting to Different Data Types������������������������������������������������������������������������������������������������� 173
The cast( ) Function������������������������������������������������������������������������������������������������������������� 174
Casting to a String��������������������������������������������������������������������������������������������������������������� 175
Casting Date Literals����������������������������������������������������������������������������������������������������������� 177
Creating a View������������������������������������������������������������������������������������������������������������������������� 177
Using Views in Microsoft SQL���������������������������������������������������������������������������������������������� 180
Summary���������������������������������������������������������������������������������������������������������������������������������� 181
Data Types��������������������������������������������������������������������������������������������������������������������������� 181
NULLs���������������������������������������������������������������������������������������������������������������������������������� 181
Aliases��������������������������������������������������������������������������������������������������������������������������������� 182
Subqueries�������������������������������������������������������������������������������������������������������������������������� 182
The CASE Expression����������������������������������������������������������������������������������������������������������� 182
Casting a Value�������������������������������������������������������������������������������������������������������������������� 182
Views����������������������������������������������������������������������������������������������������������������������������������� 183
Coming Up��������������������������������������������������������������������������������������������������������������������������������� 183

ix
Table of Contents

Chapter 6: Joining Tables������������������������������������������������������������������������������������� 185


How a Join Works��������������������������������������������������������������������������������������������������������������������� 186
Joining the Tables���������������������������������������������������������������������������������������������������������������� 189
Alternative Syntax��������������������������������������������������������������������������������������������������������������� 189
Selecting the Results����������������������������������������������������������������������������������������������������������� 191
Table Aliases������������������������������������������������������������������������������������������������������������������������ 193
Developing a Price List������������������������������������������������������������������������������������������������������������� 194
Join Types��������������������������������������������������������������������������������������������������������������������������������� 195
The INNER JOIN������������������������������������������������������������������������������������������������������������������� 197
The LEFT OUTER JOIN and RIGHT OUTER JOIN�������������������������������������������������������������������� 197
The “Preferred” Outer Join�������������������������������������������������������������������������������������������������� 199
Some Recommendations on JOINS������������������������������������������������������������������������������������� 200
Finishing the Price List�������������������������������������������������������������������������������������������������������������� 201
Joining Many Tables������������������������������������������������������������������������������������������������������������������ 202
Building a Larger JOIN��������������������������������������������������������������������������������������������������������� 204
Revisiting Some Subqueries������������������������������������������������������������������������������������������������ 209
A More Complex Join���������������������������������������������������������������������������������������������������������������� 211
Using a Self-Join����������������������������������������������������������������������������������������������������������������������� 216
Summary���������������������������������������������������������������������������������������������������������������������������������� 220
Syntax���������������������������������������������������������������������������������������������������������������������������������� 220
Table Aliases������������������������������������������������������������������������������������������������������������������������ 220
The ON Clause��������������������������������������������������������������������������������������������������������������������� 220
Join Types���������������������������������������������������������������������������������������������������������������������������� 221
Coming Up��������������������������������������������������������������������������������������������������������������������������� 221

Chapter 7: Aggregating Data�������������������������������������������������������������������������������� 223


Counting Data��������������������������������������������������������������������������������������������������������������������������� 224
Counting Values������������������������������������������������������������������������������������������������������������������� 224
How Aggregates Work��������������������������������������������������������������������������������������������������������������� 225
Counting Selectively����������������������������������������������������������������������������������������������������������������� 226
Distinct Values�������������������������������������������������������������������������������������������������������������������������� 232

x
Table of Contents

Summarizing Numbers������������������������������������������������������������������������������������������������������������� 233


Bad Examples���������������������������������������������������������������������������������������������������������������������� 235
Scales of Measurement������������������������������������������������������������������������������������������������������� 236
Aggregating Calculated Data���������������������������������������������������������������������������������������������������� 237
Other Aggregate Functions������������������������������������������������������������������������������������������������������� 239
Using Aggregates As Filters������������������������������������������������������������������������������������������������������ 240
Grouping����������������������������������������������������������������������������������������������������������������������������������� 243
Using the GROUP BY Clause������������������������������������������������������������������������������������������������ 245
GROUP BY vs. DISTINCT������������������������������������������������������������������������������������������������������� 250
Grouping with Multiple Tables��������������������������������������������������������������������������������������������������� 251
Redundant Groups�������������������������������������������������������������������������������������������������������������������� 254
Preparing Data for Aggregating������������������������������������������������������������������������������������������������ 256
Using CASE in a CTE������������������������������������������������������������������������������������������������������������ 259
Using a Join in the CTE�������������������������������������������������������������������������������������������������������� 260
Summarizing Strings����������������������������������������������������������������������������������������������������������� 262
Filtering Grouped Results with HAVING������������������������������������������������������������������������������������� 264
Using Results in a CTE��������������������������������������������������������������������������������������������������������� 268
Finding Duplicates��������������������������������������������������������������������������������������������������������������� 269
Using Aggregates on Aggregates���������������������������������������������������������������������������������������� 272
Summary���������������������������������������������������������������������������������������������������������������������������������� 275
Coming Up��������������������������������������������������������������������������������������������������������������������������� 276

Chapter 8: Working with Tables���������������������������������������������������������������������������� 277


How Tables Are Created������������������������������������������������������������������������������������������������������������ 278
Creating a Table������������������������������������������������������������������������������������������������������������������� 279
Column Names�������������������������������������������������������������������������������������������������������������������� 280
Data Type����������������������������������������������������������������������������������������������������������������������������� 281
Primary Keys����������������������������������������������������������������������������������������������������������������������� 282
Constraints�������������������������������������������������������������������������������������������������������������������������������� 284
NOT NULL����������������������������������������������������������������������������������������������������������������������������� 285
UNIQUE�������������������������������������������������������������������������������������������������������������������������������� 286
DEFAULT������������������������������������������������������������������������������������������������������������������������������� 286

xi
Table of Contents

CHECK���������������������������������������������������������������������������������������������������������������������������������� 287
Foreign Keys������������������������������������������������������������������������������������������������������������������������ 287
Indexes�������������������������������������������������������������������������������������������������������������������������������� 289
Adding Rows to a Table������������������������������������������������������������������������������������������������������������� 290
Deleting Rows from a Table������������������������������������������������������������������������������������������������������ 292
Adding More Rows�������������������������������������������������������������������������������������������������������������������� 294
Updating Rows�������������������������������������������������������������������������������������������������������������������������� 295
Altering the Table���������������������������������������������������������������������������������������������������������������������� 297
DML in Real Life������������������������������������������������������������������������������������������������������������������������ 299
Security������������������������������������������������������������������������������������������������������������������������������� 299
Front-End Software������������������������������������������������������������������������������������������������������������� 300
Summary���������������������������������������������������������������������������������������������������������������������������������� 301
Data Types��������������������������������������������������������������������������������������������������������������������������� 301
Constraints�������������������������������������������������������������������������������������������������������������������������� 301
Foreign Keys������������������������������������������������������������������������������������������������������������������������ 302
Indexes�������������������������������������������������������������������������������������������������������������������������������� 302
Manipulating Data��������������������������������������������������������������������������������������������������������������� 302

Chapter 9: Set Operations������������������������������������������������������������������������������������� 303


Unions��������������������������������������������������������������������������������������������������������������������������������������� 303
Selective Unions������������������������������������������������������������������������������������������������������������������ 307
SELECT Clauses Must Be Compatible���������������������������������������������������������������������������������� 309
Only Column Names from the First SELECT Statement Are Used���������������������������������������� 311
Sorting Results�������������������������������������������������������������������������������������������������������������������� 312
Intersections����������������������������������������������������������������������������������������������������������������������������� 314
Differences�������������������������������������������������������������������������������������������������������������������������������� 317
Some Tricks with Set Operations���������������������������������������������������������������������������������������������� 321
Comparing Results�������������������������������������������������������������������������������������������������������������� 321
Virtual Tables����������������������������������������������������������������������������������������������������������������������� 323
Mixing Aggregates��������������������������������������������������������������������������������������������������������������� 326
Summary���������������������������������������������������������������������������������������������������������������������������������� 330

xii
Table of Contents

Appendix 1: Differences Between SQL Dialects���������������������������������������������������� 333

Appendix 2: A Crash Course in PDO���������������������������������������������������������������������� 341

Appendix 3: Additional Notes������������������������������������������������������������������������������� 357

Index��������������������������������������������������������������������������������������������������������������������� 369

xiii
About the Author
Mark Simon has been involved in training and education
since the beginning of his career. He started as a teacher
of mathematics but soon moved into IT consultancy and
training because computers are much easier to work
with than high school students. He has worked with and
trained in several programming and coding languages and
currently focuses mainly on web development and database
languages. When not involved in work, you will generally
find him listening to or playing music, reading, or just
wandering about.

xv
About the Technical Reviewer
Atul Tyagi is a database developer who has worked
extensively in the field of data analytics for over eight years.
He has worked with various industries, including general
insurance and banking domains, and has contributed
significantly to several projects involving reporting,
datamarts, automation, data model development, and
project migration.
Atul is skilled in SQL, SAS, Python, and ETL tools such as
Informatica, SAS DI, Datastage, and SAS Visual Analytics. His
expertise in these areas has helped numerous organizations
effectively manage and analyze their data, leading to
improved decision-making and business outcomes. Atul has worked with leading
companies such as Accenture Solutions, Wipro Pvt Ltd, Acxiom Technologies, and EXL
Services.
Apart from his professional work, Atul is also passionate about sharing his
knowledge, cloud platforms, and data analytics. In his free time, he enjoys reading,
traveling, and exploring new cuisines.

xvii
Random documents with unrelated
content Scribd suggests to you:
Lord made heaven and earth . . . and rested the seventh day: wherefore the Lord blessed
the sabbath day, and hallowed it."

You will see it begins with the one word—

"REMEMBER!"

What are we to remember? A father goes out in the morning, and as he turns away, he
says, "Remember, children, what I have told you to do!"

So our Heavenly Father says to each one of us, about the Sundays that come every week:
"Remember! This is My Day—it is the Sunday of the Lord thy God!"

Then let us rejoice that such a day is given us. A rest from our lessons; a rest from our
work; a time when we can read a nice book in which we find something to help us about
pleasing God.

Sunday is given us to do good in. Think how our Lord, when He was on earth, went about
healing and comforting on the Sabbath Day! And He told the people "it was lawful to do
good on the Sabbath Day."

If we look out for opportunities, we can think of things to do that will help others. We can
paint texts to send to invalids or to cottages; we can put sacred pictures, if we have any,
into scrap-books for the Children's Hospital, or we can paste some white paper on a used
picture post-card, and write neatly a verse or two of a hymn, and send the cards, when
done, to cheer the wounded soldiers! Such a hymn as "Fight the good fight," or "Jesu,
Lover of my soul," or "I heard the voice of Jesus say."

An elder sister, perhaps, can show the little ones a Bible picture-book, and tell them some
simple stories about Little Samuel or Joseph. Or she can read aloud a Sunday story-book
to the others, while they paint or chalk some outlined texts.

In a large family I know, this was a very favourite occupation.

Then singing hymns! Oh, how children love hymns!

As you begin to "remember" to make God's Day a holy, happy one, you will find that there
are things to do in it, for His sake, that will make you happy, too.

It is a day for worship, for rest, for peace, and for loving ministrations for others, and you
will find that "in keeping His Commandments there is great reward."
XIX. THE POTTER'S VESSEL

THOSE who have visited the East tell us that even to-day the potter still sits at his work,
making jars and jugs to carry the precious water from the wells.

Now we must suppose ourselves entering the little courtyard where the potter sits at work,
or bending our heads to enter the shady little building or shed, where the rays of the mid-
day sun cannot reach him.

He has just brought a lump of clay, and placed it on the middle of his wheel, and with his
feet, he gives the wheel a twist, and begins to mould the great lump of clay into a round
sort of mass.
THE POTTER'S WHEEL.

So the visitor ventures to say: "May I ask what you are making, sir?"

And the potter looks up, with a half-smile, as he answers: "I am going to make a lovely
jar," and then his feet twist the wheel round and round, and the visitor stands by watching.

The potter puts his thumb into the place where the neck of the jar will be, and as he twists
and moulds, the visitor sees before his eyes the ugly bit of clay coming into an elegant
shape.

At length the jar is done, and the visitor asks another question. "What will you do, now?"
he says.

"I shall paint it with beautiful colours—"

"And then?"

"Then I shall put it into the oven and bake it, so that the shape and the colours will stand
fast."

The visitor hesitates. At length, he asks, "You do not make them all alike? Some are plain
and homely; some are beautiful, and I suppose costly?"

The potter smiles, as he rises and places his jar on a shelf out of harm's way.
"Well, sir," he says, "it's just as I choose to make them! Some are so precious in my eyes
that I love to look at them; some turn out so badly, that I have to mould the clay over
again. Just as I like, sir; just as I like! It is my clay, and my work; but I want the pieces
that I make, to come out beautiful and lovely."

I shall paint it with beautiful colours.

So the potter takes another lump of clay, and goes to his wheel again; and the visitor,
thanking him very much for his kindness, turns away thoughtfully.

Had he not read somewhere in his Bible about the Clay and the Potter?

"Yes," he said to himself at length. "It was in Jeremiah, and when I get back to my Hotel, I
will look it up."

And he found what he wanted, in the 18th Chapter of Jeremiah, where the Lord told the
Prophet to go down to the potter's house, that He might tell him there, what he was to say
to the Jewish people, who at that time were sadly disobedient, and had turned away from
God.

So Jeremiah went down to the Potter's house; and behold, he was making something on
his wheel.

But as he made it, the vessel which he was moulding was marred, or spoilt, under his
hand; so he turned, and made the piece of clay into another shape, as it seemed good to
the potter to make it.

And the Prophet stood and watched him.


Then the word of the Lord came to Jeremiah, and the Lord told him he was to go to the
people of Israel and tell them His message. That if they continued in their evil ways, He
would take them out of their own land, and from their beloved City, Jerusalem, and He
would send them to be Captives in a distant land.

And God said, "O house of Israel, cannot I do with you, as this potter has done with his
clay?"

For God loved the Children of Israel, and He wanted to make them good and beautiful, like
the potter wanted to make his jars.

But the Children of Israel rebelled against God; and though He had sent great deliverances
many times, and brought them right out of the bondage of Egypt, and into the beautiful
land of Canaan, they very quickly forgot Him again.

They forgot all His love towards them, and began to serve other gods, which they made
with their own hands; and they even sacrificed and burned their own sons on their altars.

So God sent Jeremiah with His message to them—that if they would turn away from their
evil ways and come back to Him, He would forgive them and give them every blessing; but
if they refused, then Jerusalem should be destroyed, and God would send those who were
left after the battles into a far country where they should be Captives for seventy years.

Yet even with all these solemn warnings, the Children of Israel—the Jews—refused to obey
God; and very shortly those things came to pass which Jeremiah had told them.

But God has given great promises to the Jews, and He is very patient and longsuffering.

By and by after seventy years, He brought them back in a wonderful way to their own
Land, which they again inhabited, and built cities and lived in them.

But it was not very long before they again began to depart from God's laws; they ceased
to obey those things which were plainly written in the Old Testament Scriptures; and at
last, when Jesus Christ came to earth to be their Messiah and King, they did not remember
all God had said in the Bible about Him, and they rose up against Him, and crucified the
Lord of Glory!

And so, again the Heavenly Father, who calls Himself the Potter, has had to send the Jews
out of their Land, and He is moulding them now by trials and sorrows, so that by and by
they may be purified and restored to His favour.

For when Jesus comes back to Earth, as He surely will, "they will look on Him whom they
have pierced," and will turn to Him, and be saved.
XX. JEHOSHEBA, THE GOOD AUNT
2 KINGS 11.1-21. 2 CHRONICLES 22, 23, AND 24

QUEEN ATHALIAH, the daughter of Ahab and Jezebel, was a very wicked woman.

Her son Ahaziah only reigned one year in Jerusalem, and she was his counsellor to do evil.
But at the end of the year he was slain by Jehu, and the Throne of Judah became empty.

Then Queen Athaliah determined to destroy all the Royal Princes, and ordered all the sons
of Ahaziah to be killed, in order to reign over the Kingdom herself.

But while these terrible scenes were happening, and the Princes of Judah were being killed
one after another, there was a Princess, Ahaziah's sister, who made a brave resolve, and
carried it out most successfully.

She knew that one of the King's sons, whom Athaliah had intended to kill, was a baby of a
year old, and she determined that she would do her utmost to rescue him from the
soldiers who were ordered to carry out this wicked scheme. This Princess was called
Jehosheba, and she was the wife of the High Priest, and evidently could go into the outer
rooms of the Temple.

So while the shouts of the soldiers, and the cries of those who were being murdered, were
filling the air with terrible sounds of confusion, Jehosheba stole swiftly to the place where
she thought she should find the baby boy, and hiding him under her beautiful robes she
bore him into the Temple, far away from the noise and turmoil, and she hid him in a
bedchamber, under the care of his trusted Nurse.
BORE HIM INTO THE TEMPLE.

The bedchamber was probably a little room where the mats and bedding for the priests
who lived in the Temple, were kept, and at night they were brought out and laid upon the
floor in the larger chambers; for that is the custom in the East.

No one missed the little child, for Athaliah believed that all the Royal Princes were slain. So
she immediately put herself on the Throne, and reigned over the kingdom, practising all
her wicked ways as before, in defiance of the Commands of God.

You will not wonder that she came to a very sorrowful end, as we shall hear presently.

Meanwhile, Joash, the little heir to the throne, was kept hidden safely in the Temple. You
can picture to yourselves how Jehosheba would have often gone to that far-off
bedchamber to play with her little nephew, and how she would teach him all she could, to
prepare him for the Kingdom.

It is evident also, when we read the accounts, that her husband, Jehoiada, the High Priest,
was often with the child: for by and by when six years had passed away, and little Joash
was seven years old, Jehoiada determined that he should be crowned King.

So he called the Captains of the army, and they started out all over the land of Judah, and
gathered the Levites from all the cities, and the chief fathers of the people, and they all
came up to Jerusalem.
Then Jehoiada . . . put the crown on his head.

Jehoiada shewed them the little King, and made arrangements for their guarding him on
the Coronation Day. He also armed them with spears and shields and bucklers which had
been King David's, and said to them, "Behold the King's son shall reign, as the Lord hath
said of the sons of David."

So the Captains and the Levites did exactly as Jehoiada told them, and stood on guard
about the King, with their weapons in their hands.

Then Jehoiada brought forward the little son of King Ahaziah, and put the crown on his
head, and the roll of the Testimony in his hand, and they made him King, and Jehoiada
and his sons anointed him; and those about him clapped their hands with joy, and said,
"God save the King!"

But when Athaliah, the wicked Queen, heard the shouting and rejoicing, she hurried into
the House of the Lord, and when she saw the King standing by a pillar, and the Princes and
the trumpeters around him, and all the people rejoicing, and sounding the trumpets, she
rent her clothes and cried, "Treason! Treason!"

But Jehoiada quickly commanded the Captains to seize Athaliah, and take her out of the
Temple, and to kill her with the sword outside the Courts; and there she was slain.

Then Jehoiada made a covenant with the King and all the people, that they should be the
Lord's people, and not idolaters any more; and they went into the house of the idol Baal,
and broke it down; and they broke up the altars of Baal, and his images into small pieces,
and killed the priest of Baal.

So all the people rejoiced greatly, and they brought the King to the King's house, and he
sat on the Throne of Judah.
As long as the faithful High Priest lived, Joash was a good King. Jehoiada was his
counsellor and friend, and under his advice Joash did much to repair the Temple of God.

But when Jehoiada died, Joash fell into evil company. The Princes of Judah came and
persuaded him to go to the Groves and Idols; and the end was, that he brought misery on
himself, and also on the Kingdom which he ruled.

God sent Prophet after Prophet to implore the people to return to the Lord, but Joash went
on in his wrong-doing, even to killing the son of Jehoiada, his old friend and protector.

Joash fell very sick at this time, whether from wounds or from illness, the Bible does not
say; but the servants who waited on him conspired against him, and killed him in his bed.

Oh! What a sorrowful death! No love, no tender pity, but hatred for all the evil he had done
to the Kingdom, over which he might have reigned so gloriously, had he only kept close to
the Lord God, who would surely have established his throne.

XXI. GOD FEEDS ELIJAH

ELIJAH was a great Prophet of the Lord; and to him were given more wonderful honours
than were conferred on any other Prophet.

We talk much now-a-days about deeds of bravery, and about the honours which are given
to the men who have thus distinguished themselves; and these honours are given them by
our King, and the brave deeds are spoken of from one end of the world to the other!

You will like to know what honours Elijah had?

He was allowed to go to Heaven without dying; and he was allowed long afterwards to
come back from the glory to talk with the Lord Jesus on the Mount of Transfiguration.
These wonderful "distinctions" were not given him by any earthly king, but by God
Himself; and as we follow out the story of Elijah's life, we shall ourselves, perhaps, have a
peep into that glory which Jesus is even now preparing for those who love and follow Him.

I have read that Elijah's name means "My God is Jehovah!" and it seems to me that this is
a brave motto for each one of us, "My God is Jehovah!" "For in the Lord JEHOVAH is
everlasting strength."

The first mention we have of the Prophet Elijah, who came from the land of Gilead, was in
the reign of King Ahab.

God chose Elijah, who was very brave, to rebuke the king for his many acts of wickedness.
We read that Ahab did more to provoke the Lord God than any of the other kings before
him.

One day Elijah went to Ahab and told him: "As the Lord God of Israel liveth, before Whom
I stand, there shall not be dew nor rain these years, but according to my word."

This loss of rain was doubtless sent as a great punishment for the idolatry and sin into
which the whole people of Israel had fallen.

Then the Word of the Lord came to Elijah, saying, "Turn thee eastward, and hide thyself by
the brook Cherith that is before Jordan."

God did not forget His faithful servant in the famine that was coming; and He told him He
had commanded the ravens to feed him, and that he would be able to drink of the brook.

Here, amidst the rocks and fastnesses, he was safe from the wrath of Ahab and of Jezebel,
Ahab's wife, who hated Elijah with all her heart.

And the ravens brought him bread and flesh in the morning, and bread and flesh in the
evening, and he drank of the brook.

But when the hot days came the brook began to grow less and less, because there had
been no rain, and at last the brook dried up; and then the Word of the Lord came to him
again: "Arise and go to Zarephath, near Sidon: I have commanded a widow woman to feed
thee there."

So Elijah went the long journey to Zarephath, and just outside the gate he saw a woman
gathering sticks; and, too thirsty to wait till he reached her side, he called to her: "Fetch
me, I pray thee, a little water to drink!"

And as she was going to fetch it, he called again: "And bring me a morsel of bread in thine
hand!"

But she quickly answered: "I have not any bread! I have nothing but a little meal in the
bottom of the barrel, and a little oil in a cruse; and I was gathering a few sticks to bake a
little loaf for me and my son, that we may eat it and die!"

The famine was so bad in the land that this was the last bread that poor widow would be
able to get.

But God knew all about it, and He had arranged it all in His loving way.

So Elijah, hungry and thirsty as he was, gave her God's message.


"Fear not," he said; "go and do as thou hast said: but make me thereof a little cake first,
and bring it unto me, and after make for thee and for thy son. For thus saith the Lord God
of Israel: The barrel of meal shall not waste, neither shall the cruse of oil fail, until the day
that the Lord sendeth rain upon the earth."

And she went and did as the Prophet told her, and he, and her house, had enough to eat
all the while the famine lasted.

And since then there are many widows, and many distressed and anxious families, who
have found the God of Elijah the same loving, providing God that this poor widow did.

But by and by there came a still harder trial to that widow's heart. Her precious little boy,
who had been kept alive all through the famine, was very ill, and died.

Then the poor widow was utterly hopeless, and she blamed Elijah and said it was his fault
that this dreadful sorrow had come to her.

Doubtless Elijah had told her much about the Holy God who cannot bear sin, and she
began to look at her past life, and one particular sin came up before her! She told him that
he had come to bring this sin to remembrance, and to slay her son!

But Elijah said, "Give me thy son." And he took him out of her bosom and carried him up
to the loft where he lived, and laid the child upon his own bed.

And Elijah cried to the Lord. (You see he was a man who lived in close touch with God!)
And he said: "O Lord my God, hast Thou brought evil upon the widow with whom I
sojourn, by slaying her son?"

Then he stretched himself upon the child three times. And again he cried to the Lord God,
and said: "O Lord my God, I pray Thee, let this child's soul come into him again!"

"And the Lord heard the voice of Elijah, and the soul of the child came into him again, and
he revived."

"And Elijah took the child, and brought him down . . . and delivered him unto his mother,
and said, 'See! Thy son liveth!'"

"And the woman said to Elijah, 'Now by this I know that thou art a man of God, and that
the Word of the Lord in thy mouth is truth.'"
XXII. RUTH

A LONG time ago we read of something most interesting about Bethlehem.

In the time of the Judges of Israel, before Saul or David had been made kings, there was a
man living at Bethlehem whose name was Elimelech. He had a wife called Naomi, and two
sons called Mahlon and Chilion.

But there came a famine in Bethlehem, and Elimelech and his wife and two sons went out
of Canaan and journeyed into the land of Moab.

Here the family of Elimelech settled down for ten years.

But Elimelech died, and Naomi was left with her two sons. These sons married wives in
Moab, but both of them died, and Naomi was then left a desolate widow.

By and by she heard that the famine was over in the land of Canaan, and she started with
her two daughters-in-law to return to Bethlehem.

But after they had set out on their journey, Naomi advised Orpah and Ruth to go back to
their mothers, and prayed that, as they had been so loving and kind to her sons who had
died, God would take care of them, and bless them in Moab.

Then she kissed them, and they all wept together. And they said, "Surely we will go back
with thee to thy people!"

But Naomi did everything she could think of to dissuade them, and at last, with many
tears, Orpah wished her good-bye; but Ruth clung to her.

Then Naomi used another argument: "Behold, thy sister-in-law is gone back to her people
and to her gods—return thou after her."
But Ruth said: "Entreat me not to leave thee or to return from following after thee, for
whither thou goest I will go; thy people shall be my people, and thy God shall be my God!"

So Ruth chose the God of Israel to be her God. And that God Whom she had chosen,
watched over her all her life long, and gave her great happiness and honour, as I shall tell
you by and by.

When Naomi found that Ruth was determined that "naught but death" should part them
she left off persuading her, and they two journeyed on till they came to Bethlehem.

So Boaz spoke kindly to Ruth.

The arrival of strangers at a little town in those days was a great event, and all the people
flocked out of their houses to see who it could be.

And they said, "Is this Naomi?"

But Naomi's heart failed her. She had gone out with husband and sons, and she had
returned desolate; and in her grief she said, "Do not call me 'Naomi'" (that meant
pleasant), "but call me 'Mara'" (which means bitter), "for the Almighty hath dealt very
bitterly with me!"

Poor Naomi! She forgot her sweet daughter Ruth; she forgot the God of Israel whom they
both trusted. For a little while her grief swept over her.

There lived in Bethlehem a rich man, whose name was Boaz, and he was a relation of
Naomi's husband, Elimelech.

When they found that the barley harvest had just begun, Ruth said to her mother-in-law,
"Let me go into the fields to glean corn!"
And when she reached the fields she happened on a field belonging to Boaz; but Ruth did
not know that he was her relative.

When Boaz saw Ruth among the women who had come out to glean, he asked his servant
who was set over the reapers whose damsel she was? And the servant told him that she
had come from Moab with Naomi, and he had let her glean among the reapers.

So Boaz spoke kindly to Ruth, and bade her keep near his maidens; and if she were thirsty
she was welcome to take some of the water which his young men had drawn.

Then Ruth bowed herself to the ground, and thanked Boaz for his kindness to a stranger.

But Boaz told her that he had heard all about her love to her mother-in-law, and how she
had left father and mother to come to a strange land. And then he asked the Lord God of
Israel, under Whose wings she had come to trust, to bless her, and to give her a full
reward for all she had done.

So Boaz told her to come at meal-times and share the food they had; and he gave her
parched corn, some of which she saved to carry to her mother-in-law; and when she had
had sufficient, she went back to her gleaning. And Boaz told his young men to let fall
handfuls on purpose for her, so that by evening she had gathered quite a good quantity.

When Naomi heard all the kindness of Boaz, she told Ruth that he was a near relation, and
she realized that, after all, the Lord had not forsaken her, though in her grief she had
almost thought He had!

She told Ruth to keep fast by the maidens of Boaz. So day after day, till the harvest was
over, Ruth did as Naomi bade her; and as Boaz went to and fro among the reapers, he saw
the modest and sweet behaviour of the young stranger girl, and he determined to ask her
to be his wife. So they were married; and by and by a dear little son was given to them.

And the women said to Naomi: "Bless be the Lord, which hath not left thee without a
kinsman, that his name should be famous in Israel."

So Naomi was comforted, and became a nurse to the babe who was so precious to her.

And his name was famous! For the child was called Obed, and he was in due time the
father of Jesse; and Jesse was the father of David, and through David, years afterwards,
came our Blessed Lord!

Do you not remember how the blind man cried out?—"Jesus, Thou son of David, have
mercy upon me."
XXIII. ON MOUNT GILBOA

As David left Saul, and went back to his stronghold at Engedi, he said to himself: "I shall
one day perish by the hand of Saul! There is nothing better for me than that I should
escape into the land of the Philistines, and Saul will cease to look for me."

So he went with the six hundred men who followed him, and dwelt with Achish, the king of
Gath, for a year and four months.

But, after a time, the Philistines determined to go to battle against the Israelites, and as
David and his men were very friendly with Achish, they marched in the rear of the army
which was gathered together against Saul.

But when the princes of the Philistines found David and his men among the warriors, they
very much objected, telling Achish that when the battle was joined, David would go over to
the other side and fight against the Philistines.

Achish tried to persuade them that David and his men were their friends, but the lords of
the Philistines would not consent; and David had to go back to Ziklag. It would take too
long to tell you here how he found that other enemies had invaded his home, or how he
and his men went after them, and how the Lord helped them to recover their wives and
children and all the spoil that those enemies had taken.

But it seems very wonderful that, in the great battle of the Philistines in which Saul was
killed, the Lord had sent David far away in another direction!

So the Philistines gathered themselves to the battle, and Saul and his sons and all the men
of Israel came out against them.

But the night before the battle Saul had gone to a witch at Endor, and asked her to bring
up Samuel to speak to him. Both he and the witch were very frightened when Samuel
came up—an old man wrapped in a mantle—and Samuel told Saul that God had given the
kingdom to David, and that he and his sons would be killed on the morrow.
Both he and the witch were very frightened when Samuel came up.

So the battle took place the next day on Mount Gilboa; and the Philistines followed hard
upon Saul and his sons, and Saul was sore wounded by the archers.

Then Saul besought his armour-bearer to kill him with his sword lest his enemies should
come and mock him. But his armour-bearer would not, for he was sore afraid.

Then King Saul took his own sword and fell upon it and died. And when his armour-bearer
saw that he was dead, he fell upon his sword too, and died with him.

So Saul died, and his three sons and all his men, that day together.

When the rest of the army who were on the other side of the valley and on the other side
of Jordan saw that Saul and his sons were dead, they fled, and forsook their cities, and the
Philistines came and dwelt in them.

On the next day, the Philistines came to the battlefield to strip the slain, and when they
found the king and his sons, they cut off Saul's head and stripped off his armour, and sent
the news to all the country round; and they published it in the houses of their gods and
made a great rejoicing.

They hung the dead bodies of Saul and his sons on the wall of Bethshan; but when the
inhabitants of Jabeshgilead heard of what the Philistines had done, all the valiant men
arose and travelled all night and took the bodies of Saul and his sons down from the wall;
and the men of Jabesh burnt the bodies, and buried their bones under a tree in Jabesh,
and made a great mourning for their fallen king for seven days.
This is a very sorrowful story. Saul had set out well, and he had everything in life before
him.

He was a great warrior; he had fought many battles against the Philistines and other
enemies on every side; but he spoilt all by one great sin. This was the sin of disobedience.
He had disobeyed God's direct command.

Not long after Saul was made king, God told him to go and utterly destroy the Amalekites,
leaving none behind, not even flocks and herds, or anything that was theirs.

But though Saul went, and gained a great victory over them, he disobeyed God in the end;
for he saved alive the king and the best of the flocks and herds, and all that was good, he
kept.

Then the Lord sent Samuel to Saul. And Saul hastened to meet him with the words:
"Blessed be thou of the Lord! I have performed the commandment of the Lord!"

But Samuel answered: "What meaneth then the bleating of sheep in my ears?"

And Saul answered: "The people spared the best of the flocks to sacrifice to the Lord."

And Samuel said to Saul: "Stay, and I will tell thee what the Lord has said to me this
night."

"When thou wast little in thine own sight, wast thou not made head over the tribes of
Israel? And the Lord sent thee on a journey, and said, 'Go and utterly destroy the sinners
the Amalekites, and fight against them until they be consumed.'"

"Wherefore then didst thou fly upon the spoil, and didst evil in the sight of the Lord?"

"Hath the Lord as great delight in burnt offerings and sacrifices, as in obeying the voice of
the Lord?"

"Because thou hast rejected the word of the Lord, He also hath rejected thee from being
king."

This is the reason why God gave the kingdom to David, and allowed Saul to be killed on
Mount Gilboa.
XXIV. ABSALOM

THE story of Absalom cannot be anything but a sad one.

He was the third son of David, and his mother's name was Maachah, who was the
daughter of the King of Geshur.

He inherited great beauty from both his father and his mother, and was evidently the idol
of David's heart. But with all his fascinating beauty, he was not a good man.

His mother was a heathen princess, and Absalom had not been taught in her home the
justice, the purity, the forbearance, the love, and the fear of God, which ought to be the
ruling-spring of our lives.

His one thought was how to please himself, no matter what impediments stood in his way.

By and by he had cause to be angry with his half-brother Amnon, who had acted very
wickedly; but instead of bringing him to be judged by the law, Absalom secretly plotted to
kill him.

For this purpose, he invited all the king's sons to be present at a great feast; and he gave
his servants orders to set upon Amnon and kill him, when he gave a sign to do so after
supper.

When the rest of the king's sons saw this dreadful deed, they all fled on their mules in hot
haste; but while they were on their way back to Jerusalem, the tidings reached David that
all his sons were dead!

The sorrowful king tore his clothes, and lay upon the earth, and all his servants stood by
with their clothes rent.

But Jonadab, David's nephew, tried to comfort the king, by assuring him that only Amnon
was dead.

While Jonadab was persuading the king that it was not as bad as had first been told him,
they saw a great company coming down the hillside, and Jonadab said to the king:
"See, it is as I said; there are the king's sons!"

Then all David's sons wept for the sad thing which had happened, and David and his
servants wept very much.

But Absalom had fled, and had gone to his mother's relatives at Geshur, where he stayed
three years. And David mourned for his son every day.

At length Joab, the captain of the host, saw that David's heart was bound up in Absalom,
and he persuaded David to send for him to Jerusalem. But though David allowed him to
return, he did not see his face for two whole years.

This made Absalom very angry, and because Joab would not carry his messages to the
king, Absalom told his servants to set fire to a whole field of Joab's wheat: at last Joab
consented to speak to the king, and finally Absalom was allowed to see his father: and
David kissed him.

But what do you think Absalom did to that loving, devoted father?

He at once set about trying to seize the kingdom for himself!

He sat in the gate of the city and told the people who passed in and out, that if he were
king he would see that every grievance was righted; and he kissed the people as they
came and went, and stole their hearts!

Then Absalom asked permission to go to Hebron, and he sent spies all through the land to
tell every one that at the sound of the trumpet every one was to say, "Absalom is King in
Hebron!"

Thus the conspiracy grew and grew; and I cannot tell you how many sorrowful and wicked
things were done while Absalom tried to get the kingdom!

David was indeed at his wits' end; but he remembered that the Lord was his Refuge, and
he prayed that the Lord would defeat the counsel of those who were plotting against him.

And God answered his prayer.

At length Absalom came out against his father with a large army. There was a great battle:
but the people begged David not to go to the battle himself, but to let them fight for him,
and for the kingdom.

So David sat in the gate: and as his armies passed through ready for battle, he said to
Joab, and to all the captains of the host: "Deal gently with the young man, even with
Absalom!" And the people heard him.

So the soldiers went forth into the country, and by and by the battle was chiefly fought in a
large wood, where many of Absalom's army were killed.

As Absalom was riding quickly in the wood to escape from the soldiers, he went under an
overhanging tree in his haste, and his head caught in the boughs and he could not
extricate himself. The mule went on and he was left hanging there.

Some one hurried to Joab and told him, and Joab, disregarding the earnest entreaty the
king had given him, took three darts and thrust them through Absalom's heart.
So he died, and they put his body in a pit in the wood and threw a great heap of stones
upon it.

Absalom had built himself a great tomb in the King's Dale, but he was never laid in it. Oh,
the sorrow of that ending!

When the messengers came in from the battle, as David sat near the gate and watched,
his first question to each runner was: "Is the young man Absalom safe?" And when they
broke it to him, that Absalom had died and the victory had been complete, David turned
from them, and made his way up, weeping, to the chamber over the gate, and as he went,
he said:

"O my son Absalom, my son, my son Absalom! Would God I had died for thee, O Absalom,
my son, my son!"

XXV. THE DISOBEDIENT PROPHET


1 KINGS 13
LONG ago, soon after the Children of Israel came out of Egypt, they asked Aaron to make
a Golden Calf for them to worship, which could be carried in front of them, and would, they
hoped, lead them into the Promised Land. But we know how dreadfully they sinned in this.

And five hundred years after that, Jeroboam, King of Israel, made two Golden Calves, and
built two altars, one in Dan at the North of Palestine, and the other in Bethel at the South
of his Kingdom.

He told the people of Israel that it was too far for them to go to worship at Jerusalem,
three times in the year, and that they could go instead to worship his Golden Calf, and
could offer sacrifices upon the altars he had built.

Now God had told the Jews that Jerusalem was the place He had appointed for Worship;
and also that only God's Priests, the sons of Aaron, were to offer either Sacrifices or
Incense to Him.

One day, when King Jeroboam was himself offering incense on the altar he had made in
Bethel, a Prophet of the Lord was sent to him with a message from God.

And this was the message—That one day, on this; very altar, the priests whom Jeroboam
had made from the lowest of the people, should be offered, and their bones should be
burnt upon this altar.

God gave a Sign, by which King Jeroboam should know that the Prophet's words were
true, and that he had been sent by God.

This was the Sign. This altar of Jeroboam's should be rent—torn in pieces—and the ashes
should be scattered on the ground.

King Jeroboam was very angry at the message, and he tried to seize the Prophet, but his
hand dried up, and he could not use it.

And the Sign came to pass at once, for the altar fell to pieces and the ashes were
scattered.

Jeroboam was very frightened, and begged the Prophet to ask the Lord to restore his
hand.

And the Prophet did; and Jeroboam's hand was made quite well again.
A Prophet of the Lord was sent to him with a message from God.

Then the King pressed the Prophet to come in to refresh himself, and to receive a reward.

But the Prophet answered that the Lord had strictly forbidden him to eat bread or drink
water in that place. So he turned away, to go back by another road, as the Lord
commanded him.

But now a great temptation met him.

For as the Prophet was turning away from Bethel, an old Prophet who lived there, thought
he would ask him to come back and rest at his house. He had heard how the Prophet had
cried against the Altar, and he longed to hear all about it.

But the Prophet again explained that the Lord had forbidden him to eat and drink in that
place.

Then the Old Prophet lied to him, and said that an Angel had told him he was to ask him
home to refresh him.

So the Prophet listened to his fellow-prophet, instead of obeying God, and he turned back
and went in, and ate and drank.

But when he had finished the meal, the Word of the Lord came to the Old Prophet, with a
terrible message to the disobedient man.

"Forasmuch as thou hast disobeyed the Lord, and hast not kept the Commandment which
the Lord thy God commanded thee . . . thy carcase shall not come to be buried in the
sepulchre of thy fathers."

So the Old Prophet gave the message, and he sorrowfully saddled the ass of the
disobedient Prophet, and sent him forth on his return journey. But very soon a lion met
him in the way, and slew him; and his body lay by the roadside, and the lion and the ass
stood by, but the lion did not eat either of them.

By and by people passed that way, and they hastened to the city to tell what they had
seen.

THE DISOBEDIENT PROPHET.

Then the Old Prophet told his sons to saddle his ass, and he hurried along the road until he
came to the spot where the dead Prophet lay. And he found all as he had been told, and
saw that the Lord had not allowed the lion to touch the dead man, or the ass.

Then the old man laid the body of the Prophet on his ass, and brought him back to bury
him in his own grave; and he mourned bitterly for him, for he knew he had tempted him,
and had been the cause of his death.

He charged his sons, that when he came to die, they were to bury him in the same grave
with the Prophet; and he added a solemn assurance that the words of God which the
Prophet had uttered against King Jeroboam's altar in Bethel, and against the other
idolatrous places which he had built, should surely come to pass.
All this was literally fulfilled three hundred years after, in the reign of Josiah, the good
young King. We read the account of it in three verses in 2 Kings 23.15-18.

But King Jeroboam, knowing of this Prophecy, remembering as he must that his withered
hand had been healed by God, did not set his heart to seek God and to find forgiveness.

He went on in his evil ways all his life, until at length we read in the Bible the name by
which he was known after his death, "Jeroboam, the son of Nebat, who made Israel to
sin."

This long ago story speaks an ever-living lesson.

The God who commands will enable us to obey. Let us seek Him with all our hearts: let us
learn His will in the Bible, and then the promise to each one of us will come true—

"To him that soweth righteousness, shall be a sure reward."

XXVI. THE LORD ANSWERS ELIJAH BY FIRE


1 KINGS 18, 19

THEN after a long time, the word of the Lord came to Elijah in the third year of the famine,
saying to him, "Go, show thyself to Ahab; and I will send rain upon the earth."

So Elijah went back from Zarephath, and came down to Samaria to show himself to Ahab;
and the famine was very sore there.

Ahab had a trusted servant called Obadiah, who was governor of his house; and this man
"feared the Lord greatly."

That meant, he did that which would please God, and earnestly obeyed Him in all things.
Once, when the wicked queen, Jezebel, tried to kill all the Prophets of the Lord, Obadiah
took fifty of them and hid them in a cave, and fed them with bread and water, and so
saved their lives.

So because the famine was very terrible in Samaria, Ahab called Obadiah, and told him
that they would both go out into the country with the horses and mules and find all the
brooks and streams that were left, where a little grass might be growing, to save the
horses alive.

Ahab went one way and Obadiah another, and as Obadiah was seeking for water, he met
Elijah, who was on his way to Ahab, as the Lord had told him. When Obadiah saw him, he
bowed himself to the earth before God's Prophet; and then Elijah said, "Go and tell thy
lord that Elijah is here."

Obadiah hesitated very much to carry this message, as he was afraid that the Spirit of the
Lord might carry Elijah away, so that he could not be found. He reminded Elijah that he
had "feared the Lord" since he was a child, but that Ahab would certainly slay him if he
carried such a message to him as that!

Then Elijah promised him, that he would surely show himself to Ahab that very day.

So Obadiah went and told Ahab, and the king came out to meet Elijah.

Then Ahab said to him, "Art thou he that troubleth Israel?"

And Elijah answered, "It is thou and thy father's house that have troubled Israel, because
ye have forsaken the Lord's commandments and have worshipped Baal!"

Then he told Ahab to gather together the people, and all the four hundred and fifty
prophets of Baal, and the four hundred prophets of the grove, who sat down daily at
Jezebel's table, and to take them to Mount Carmel, and meet him there.

So a number of the people, and all the prophets of Baal, came together to Mount Carmel.

And Elijah came to the people, and he said, "How long do you mean to halt between two
opinions? If the LORD be God, follow Him! but if Baal, then follow him."
Then the fire of the Lord fell, and consumed the burnt sacrifice.

And the people did not answer a word.

Then Elijah said, "I am the only Prophet of the Lord, and Baal's prophets are four hundred
and fifty. Let them therefore give us two bullocks, and let them choose one for themselves
and slay it, and dress it, and put it on the altar, with no fire under."

"And I will slay and dress the other bullock, and put it on the altar, and put no fire under.
And the God that answereth by fire, let Him be God!"

So the priests of Baal took their bullock and did as Elijah had said; and they cried unto the
name of their god from morning until noon, saying, "O Baal, hear us!"

But there was no voice nor any that answered. And they leaped upon the Altar which was
made.

Then Elijah mocked them, and told them to cry aloud, as their god was talking, or on a
journey, or asleep, and must be awaked! And they cried aloud, and cut themselves with
knives. And thus they went on till the time of the evening sacrifice. But there was neither
voice, nor any to answer, nor any that regarded.

Then Elijah said to all the people, "Come near unto me."
And he repaired the Altar of the Lord that was broken down, and built it up with twelve
stones for the twelve tribes of Israel; and he cut a deep trench round the Altar, and put the
wood in order, and cut the bullock in pieces and laid him on the wood.

Then he told the men to fill four barrels with water, and to pour it on the burnt sacrifice
and on the wood; and this he ordered to be done three times, so that the water ran all
about the Altar; and he filled the trench with water.

Elijah knew what his God, Jehovah, was going to do, and what a glorious ending there
would be!

So at the time of the evening sacrifice Elijah drew near to the Altar and prayed: and he
said, "Lord God of Abraham, Isaac, and of Israel, let it be known this day that Thou art
God . . . and that I am Thy servant, and that I have done all these things at Thy word."

"Then the fire of the Lord fell, and consumed the burnt sacrifice, and the wood, and the
stones, and the dust, and licked up the water that was in the trench."

"And when all the people saw it, they fell on their faces: and they said, The Lord, He is the
God; the Lord, He is the God!"

"And Elijah said unto them, Take the prophets of Baal, let not one of them escape! And
they took them and brought them down to the brook Kishon." And they were all killed. The
children of Israel had acknowledged their God at last!

Then Elijah turned to Ahab the king, who, like the people, had cast himself in awe and
reverence upon the ground. And he said to Ahab, "Arise, and eat, for there is a sound of
abundance of rain!"

XXVII. JOSHUA'S COURAGE


JOSHUA 1.1-18
After the death of Moses, when the Lord, Himself, had buried His faithful servant, the Lord
came to Joshua and told him that he was to be the one who should lead the Children of
Israel into the Promised Land.

We hear of Joshua many times as we read the life of Moses.

He shared the glorious triumph when the Children of Israel were brought out of Egypt; and
soon after that, Moses chose Joshua to lead the people to fight against Amalek.

Next we hear of him as the trusted servant (or minister, as it is called in the Bible), who
went up with Moses to the Mountain called Sinai, when Moses received the Ten
Commandments from God.

Joshua did not go all the way with Moses, but waited somewhere on the mountain till
Moses should come down from talking with the Holy God.

And as they went down again, it was he who saw the Children of Israel worshipping the
golden calf below.

Next, Joshua was one of the twelve spies who were sent to search out the Land; and you
will doubtless remember that ten of these spies brought a bad report, and only two of
them, Caleb and Joshua, brought a good report.

We see Joshua's splendid courage through all these circumstances.

He trusted God with all his heart, and the Lord was his sure Refuge and constant Helper.

And it is very wonderful to remember, that among the Israelitish men who came out of
Egypt and wandered in the Wilderness for forty years, the only two who entered the
Promised Land were Caleb and Joshua, the two faithful spies! All the rest of the Israelitish
men who came out of Egypt died in the Wilderness for their disobedience, and only their
children entered the Promised Land.

It is a very solemn thing to be disobedient to God.

So as I said, the Lord came and spoke to Joshua, and told him he was to lead the people
into the Land of Canaan.

One day soon after this, Joshua sent two spies to bring back word what kind of a land it
was which he had to conquer. When they came to Jericho they came to the house of a
woman named Rahab, and lodged there.

But the King of Jericho heard of it, and sent to Rahab to give up the men to be killed.

But Rahab had heard of all the wonders that the Lord had done for His people, in bringing
them out of Egypt; how He had dried the Red Sea for the people to pass over, and of other
great victories; and instead of giving up those two Israelites to the King of Jericho, she
quickly hid them on the flat roof of her house, under a lot of flax stalks, and when the
messengers from the King came, they did not find them, and Rahab told the King's soldiers
that they had better seek the men on the road to Jordan, as quickly as they could.

So the King's men went away to look for them, and the City gates were shut, and all was
quiet again.
Then Rahab went up to the roof and told the spies that they must escape at once; and she
begged them to promise her faithfully, that when God had given them the Victory, which
she was sure He would do, that they would save her life.

So the men told her to bind a scarlet cord in her window which was on the outer wall, that
they might recognise the place; and she let them down in the night through this window,
and they got away.

All this the men faithfully carried out, and we read in the 11th of Hebrews, written nearly
1500 years after, that it was by faith that Rahab saved the spies, and by this saved her
own life too.

God loves for us to have faith in Him! And it was this faith in God which made Joshua
courageous all his life.

So Joshua and the people crossed the Jordan and entered into the Land, and came to
Jericho; and one day when Joshua was standing viewing the strength of the City, suddenly
he found Someone by him with a drawn sword in His hand.

So Joshua went to him at once, and asked "if he were going to fight for the Israelites or for
their enemies?"

And the Stranger said: "Nay, but as Captain of the Lord's Host am I now come."

Then Joshua fell on his face and worshipped, for he knew that this was the Lord Who was
speaking to him, and Who had taken the Supreme Command!

No wonder that when Joshua was old, and knew he was going to die, that he called all the
Israelites together, and rehearsed all the wonderful doings of the Lord; and that he begged
them with all his strength to serve and obey the Lord with all their hearts.

CHOOSE YE THIS DAY.


And Joshua set up a great Stone to be a Witness to them, that they had promised to love
and obey God; and he said the Stone would remind them, lest they should forget their
promise and turn back from serving God.

So the Israelites promised to be faithful, and while the elders who outlived Joshua were
alive, they did follow the Lord. But after a time they began to forget, and this brought a
great deal of sorrow upon them.

Perhaps you think within yourselves, "I should like to obey God, and follow Him! I wonder
how I could begin?"

Think of Joshua. He followed the Lord wholly—which meant with all his heart. That was the
first thing. So you can pray, "Take my heart, Lord Jesus, and help me to follow Thee!"

Then he obeyed whatever God told him to do. And whatever Command you find in the
Bible, as shewing you God's Will—do it!

You might also like