I have three tables, with these fields: classes: class_id | name | grade classes_students: class_id | student_id students: student_id | name Classes has a 1:n relationship with Students, so one …
Tag: sql
Meaning of “Select tables optimized away” in MySQL Explain plan
What is the meaning of Select tables optimized away in MySQL Explain plan? explain select count(comment_count) from wp_posts; +—-+————-+—————————+———————…
How to return empty groups in SQL GROUP BY clause
I have a query to return how much is spent on-contract and off-contract at each location, that returns something like this: The problem is, I only get one row for locations that are all ad-hoc or all contracted expenses. I’d like to get two rows back for each location, like this: Is there any way I can …
What’s “.” in postgresql dump file?
I have a Postgresql dump file which i’m trying to restore. I get this error regarding an invalid data i guess. ERROR: invalid input syntax for integer: “.” and when i checked the file, there are …
Saving changes after table edit in SQL Server Management Studio
If I want to save any changes in a table, previously saved in SQL Server Management Studio (no data in table present) I get an error message: Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#…
Join 2 Tables and display everything
I have 2 simple tables: table a: id | txt —+—- 0 | aaa 1 | bbb 2 | ccc table b: id | tel —+—- 0 | 000 2 | 111 I am trying to join 2 tables like this: SELECT a.*,b.* FROM a,b …
Which is the most common ID type in SQL Server databases, and which is better?
Is it better to use a Guid (UniqueIdentifier) as your Primary/Surrogate Key column, or a serialized “identity” integer column; and why is it better? Under which circumstances would you choose one over …
Variables in TOAD scripts
I have a SQL script that is being executed in TOAD. Currently, I have it laid out with just statement after statement, thusly: And so on. Some of the where clauses end up being repetitive because I have complex inner queries to get particular IDs to operate on. I’d like to capture the ID in the beginnin…
Seeing the underlying SQL in the Spring JdbcTemplate?
I am learning about the wonders of JdbcTemplate and NamedParameterJdbcTemplate. I like what I see, but is there any easy way to see the underlying SQL that it ends up executing? I’d like to see this for debug purposes (in order to for example debug the resulting SQL in an outside tool). Answer The Sprin…
Fetching 3 tables at a time, retrieve only the table which matches the condition (SQL)
I have 3 tables: WATER_TENDER,ENGINE and TRAILER. All of them have the EQ_ID as primary key and some other attributes, different for each table. for example, EQ _ ID=’WT-123′ points a row inside the …