Skip to content
Advertisement

Tag: sql

SQL Statement Help – Select latest Order for each Customer

Say I have 2 tables: Customers and Orders. A Customer can have many Orders. Now, I need to show any Customers with his latest Order. This means if a Customer has more than one Orders, show only the Order with the latest Entry Time. This is how far I managed on my own: This of course returns all Customers with

What is the difference between HAVING and WHERE in SQL?

What is the difference between HAVING and WHERE in an SQL SELECT statement? EDIT: I have marked Steven’s answer as the correct one as it contained the key bit of information on the link: When GROUP BY is not used, HAVING behaves like a WHERE clause The situation I had seen the WHERE in did not have GROUP BY and

How to create relationships in MySQL

In class, we are all ‘studying’ databases, and everyone is using Access. Bored with this, I am trying to do what the rest of the class is doing, but with raw SQL commands with MySQL instead of using Access. I have managed to create databases and tables, but now how do I make a relationship between two tables? If I

Is RIGHT JOIN Ever Required?

Do any queries exist that require RIGHT JOIN, or can they always be re-written with LEFT JOIN? And more specifically, how do you re-write this one without the right join (and I guess implicitly …

How do you OR two LIKE statements?

I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE ‘str1’ OR LIKE ‘str2’) AND col2 = num results in a syntax error SELECT col FROM db.tbl WHERE page LIKE (‘str1’ OR ‘…

Advertisement