Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Coding in SQL, Python, VBA, JQuery and OfficeScript using AI tools Part two of an eight-part series of blogs |
---|
One of the immediate and obvious ways to use AI tools is to boost your productivity as a programmer. This blog shows how you can use ChatGPT 4 and Google's Bard to write programs in SQL, Python, VBA, JQuery and Office Script (probably the 5 languages Wise Owl use most).
|
As a quick reminder, here's what I want my AI tool to help me to do:
"Write an SQL program for SQL Server to show the most-read books, joining a table of authors and a table of books together"
I deliberately haven't said how the tables are joined together, nor what they (or their columns) are called; you have to leave something to your AI tool's imagination!
What I like about this answer is that it states the assumptions used, and then explains afterwards how the query was written:
ChatGPT hasn't used any table aliases, but otherwise this is well formatted and constructed.
However, the big problem with this query is that it almost certainly doesn't answer my original question. I want to group by each author and show the number of books each author has written using the SQL COUNT function - a distinction which has passed ChatGPT by.
Bard took less than a fifth of the time to produce this answer:
Initially I thought this query was better than ChatGPT's version - but then I looked more closely.
There's a lot more to say about this response, because it contains a lot more detail. Here are the good things:
Good point | Details |
---|---|
Aliases | I like the way that Bard has given aliases to the tables, even though they aren't radically different from the original names! |
Formatting | The SQL is well-indented and easy to read |
Sample output | Giving sample output from the query is a great idea |
However, this query would be less useful than the ChatGPT one, and more confusing if you didn't understand SQL. There are 3 main problems:
Problem | Notes |
---|---|
Table structure | While ChatGPT doesn't complicate the question enough, Bard overcomplicates it by introducing 3 tables. I've tried my hardest to make sense of these but can't. If you know SQL well this won't be useful to you, and if you don't the joins used will just confuse you. |
Explanation | The notes at the bottom are a great idea, but I don't think they are accurate: SQL doesn't use one join at a time to create a new table (or even if it does this internally, it's still not a useful way to describe what's going on). |
Syntax | Bard has slipped in LIMIT 10 at the end which may be standard SQL but isn't used by the dialect of SQL used by SQL Server (T-SQL), for which you would use SELECT TOP 10 instead. |
Despite it taking longer to produce an answer, I prefer ChatGPT's solution. If two human programmers gave me these answers I would feel that the first person knew SQL and knew what they were talking about, but the second one was just winging it!
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.