Names of Tab from SQL Queries
I will run 3 - 7 queries all using the same base table for searching. The results is I get multple tabs with the same name on the tab.
Is there a way to have the tabs named something a little more useful?
Seeing something other than the table to let me know what it is, is more useful.
Password Check, URL with Email, Banned
Just examples.
Add postfix to query result tabs so captions are unique. See http://www.heidisql.com/forum.php?t=10493
Please read my above comment - I added the #2, #3 ... postfix for exactly that situation.
The name of the snippet or saved query would not help, as that is the same for all results, isn't it? You do not execute different snippets for each result grids. By the way, we're not talking about query tabs - what DB Phantom means is the tab captions of the result grids in one query tab. One query tab can have multiple result grids, one grid per result, e.g. if you exceute such queries at once:
SELECT * FROM table1;
SELECT * FROM table2;
/**
* Monthly Sales Query
*
* @label Monthly Sales
*/
SELECT sum(*) AS total
, month(sell_date) AS month
FROM sales
GROUP BY month;
/**
* Yearly Sales Query
*
* @label Yearly Sales
*/
SELECT sum(*) AS total
, year(sell_date) AS year
FROM sales
GROUP BY year;
Please don't use my queries as example of good SQlJust indicating how the doc blocks could be used. It would genuinely be useful to me, and I'm sure others too
IMHO, creating a annotation syntax with its corresponding documentation, parser and use cases goes far beyond the abilities that are reasonable to expect from such a tool. I can't think of any other usage apart from running reports and if we want HeidiSQL to be a decent reporting tool it'll lack tons of other basic features.
If you need to run those reports regularly you should invest a few hours writing an application, possibly a PHP-driven web site or even an Excel spreadsheet.
Heidi is an excellent tool that I've been using for donkeys, but there's no single feature that makes it a killer app, but rather a collection of MANY small features that just makes it indispensable, IMHO. Being able to label the tabs in a multi-query is just another small feature that I'd love to have. It's hardly a deal-breaker, but it would make it much simpler to read the results. The alternative for me is to have the results contain a field that describes what I'm looking at (so making the beginning of the query SELECT 'YEARLY') for example. That sucks.
I came here because I was searching for a way to help me differentiate the different tabs.
See attached image example.
I have several Selects and the first one is from "vw_SomeView". Every tab is labeled "vw_SomeView" even though all of the other selects are from other tables.
I have a similar use case. I paste in a query that has 7 selects. If I can name the tabs then I can easily see what is what. Otherwise I have to check tab position against position of the select command. That's not too hard, but when mentally juggling other things it is a distraction.
I find HeidiSQL a very good tool and this would be a useful addition for me.
On HeidiSQL Help I see a solution, but my queries aren't as simple as the example.
I'm hoping I'm missing something.
Here's one of my queries: select from(select date(FROM_UNIXTIME(joinStamp-83600)) as date, count(*) from base_user group by 1 order by date DESC LIMIT 20 ) sub order by date ASC;
*I'm a new user, so I can't include the reference - so search google for: heidisql Screenshot: Multiresults
So I found I way to make this work. instead of doing a query like the following:
select col1, col2 from table1
where col1 is not null;
change it up to be like this:
select col1, col2 from (select col1, col2 from table1) as 'WhateverLabel'
where col1 is not null;
and the tab will show up as WhateverLabel. It's a little redundant, but at least the tabs are labeled what you want.
Hope this helps
You would have to write a comment just to have the tab named after it. Isn't that manual work for the user for a minimal effect?
When you do an important updates of data you need to be 100% sure where goes each bit of data and from which tab you take this data. But when there are users#1 users#2 you have to remember what you need to do with #1 and #2. But if you once named your tabs you then can use them later no matter how far thought process gone.
Or use your select statement to create a temp table named resultset1 and then select * from it afterward, and tab will be named more specific
Sure, but that's no good if you want to update a row.
I'd favour a comment directly before the query that HSQL uses to name the tab e.g.
# My Tab 1
select * from etc
If it's not there then use default naming, if it's too long than truncate.
Cheers Muzza
I assume by the "somealias" work around you mean thstolte's post, right? If so, I try that and get an error (see screenshot). I'd love a way to add a comment above the query so I could identity the query result tab name easier.
(Using Version 11.0.0.5919 (64 Bit)) Thank you!
I guess the version has been updated so that you don't need the quotes around the label anymore. Try the following and it should work:
select mmcontactid from (select mmcontactid from tblnameContactCSIs) as whateverlabel
where mmcontactid is not null
Yes this would be a nice-to-have. I'd put a bounty up for it if ansgar supported bounties. thstolte's solution worked for me by the way.
Even if the tab was named after the alias of the first table in the query, that would be great. Surely that would not require a large change in the codebase?
So for:
SELECT height, giantswhocanclimb
FROM cliffs AS cliffsofinsanity
WHERE location = 'insanity'
The tab would be labeled "cliffsofinsanity" instead of 'cliffs'?
Just an idea.
Anyways, thanks a gazillion for making HeidiSQL!!!
I will this really appreciate. I have many queries with several selects included. It will be very easy and fast to add everywhere inside suggested agreement such -- NAME: test
@ansgar, please do it. It will be very helpfull for all of us begging :-). No problems for others.
OMG Dudes! I've been using HeidiSQL for years (love it), and have just completely accidentally discovered a rather hacky way of naming result tabs. Just precede the query with a comment in the format 'from' <label>. It's ugly, but it's going to make my life slightly jollier - see my little clippet snippet... X
'OMG Dudes! I've been using HeidiSQL for years (love it), and have just completely accidentally discovered a rather hacky way of naming result tabs. Just precede the query with a comment in the format 'from' <label>. It's ugly, but it's going to make my life slightly jollier - see my little clippet snippet... X'
This only works if UNION is present in SQL :-/
It would be great if we could change the name of the TAB in the query-windows programmatically.
I tried this in order to force the name 'TO DO' - but it does not work - it still shows 'Result #1':
-- NAME: TO_DO
SELECT -- TO_DO
TO_DO.TO_DO
FROM (SELECT 'Please undo...' AS TO_DO) TO_DO;
Support naming result tabs per "-- name: xyz" comment. See https://www.heidisql.com/forum.php?t=10493
I have just tried this nice feature. In simple cases it works well, but as soon as the queries become more complicated, the tab name becomes very wide. Here some queries to test: test1 works fine, 2
-- NAME: test 1
SELECT table_schema, table_name FROM information_schema.tables a LIMIT 1;
-- name: test2
SELECT table_schema, table_name FROM information_schema.tables a
WHERE EXISTS(SELECT 1) LIMIT 1;
-- name: test3
SELECT table_schema, table_name FROM information_schema.tables a
WHERE EXISTS(SELECT * FROM information_schema.columns b
WHERE a.TABLE_NAME=b.table_name AND a.table_schema=b.table_schema) LIMIT 1;
-- NAME: test 4
SELECT b.table_schema, b.TABLE_NAME, b.column_name
FROM information_schema.tables a INNER JOIN information_schema.columns b
on a.TABLE_NAME=b.table_name AND a.table_schema=b.table_schema
LIMIT 1;
Here is the result of running all queries in a single batch. Tab test 4 cannot be seen!
queries test 4 and test 1
Should not happen, even if there are spaces behind the "name: test2". HeidiSQL trims the result name which should remove spaces.
Anyway, could you please check whether you have trailing spaces in the comment?
I checked the statements, there are no trailing spaces. The repo in my previous note is the very same.
Fix too greedy expression for finding result name. See https://www.heidisql.com/forum.php?t=10493
@belanp You need to separate the queries with a semicolon, at least after the SELECT, so the "name:xyz" is bound to the query inside:
DECLARE @x INTEGER -- name: Result 1 SET @x = 1 SELECT 1 WHERE 1= @x; -- name: Result 2 SET @x = 2 SELECT 2 WHERE 2=@x;
sorry, but not working: / SQL error (137): Must declare the scalar variable "@x". /
@belanp You need to separate the queries with a semicolon, at least after the SELECT, so the "name:xyz" is bound to the query inside:
It is not working on MS SQL AZURE. If you use ";" semicolon there, then variable is unknown in second select a produce ERROR. Could you please use for parsing only comment "-- name: XYZ". No semicolon is needed there for parsing...
How about using the table alias (for example FROM table_name AS table_alias ) for the name of the query's tab? I am only getting "Result #1 ... Result #2...etc - which doesn't even use the name of the primary (or in my case, only) table I'm selecting from. I attached a screen shot showing this along with the overly simple bit of code I use that checks the call_log table to see how recent the data is there (since these are supposed to be real-enough-time mirror servers - but sometimes lag - and I like to check before running anything time-sensitive against them). Like a previous poster, I have been doing this positionally - remembering which SELECT statement came in what order - which isn't that difficult - but - would definitely be easier if they were named from the name of the FROM table's alias...that way we would be in FULL control of the tab's name...thanks!
Semicolon "destroys" declaration of the variable, but we all use the same value of variable on several selects in the same script. So we cannot use semicolon. We need to set variable value only once at the top of script, instead of 10 times, because we always change this value manualy, before we run this script.
When we do not use semicolon Heidy stil gives us different tabs for each (main) select. But we are not able to give them meaningful names.
Just collect "List of tab names" of all tabs defined TAB names in script. Then you generate TABs with results in Heidy frontend. And then give them names from the "List of TAB names" - one by one. It's easy. Furthermore we can define the "List of names" anytime, for example at the begin of the script, if it is problem to collect them during parsing rows. Like: -- list of tab names: "aplles", "berries", "melons" We just need the way how to give names for the TABS in the comments. Nothing more. Thanks a lot for you work with Heidy.
Looks like a nice extension to that "-- name:" comment.
Next build supports a new "-- names:" comment, and please note the plural "s":
- will be splitted by comma
- will be used to populate the result tab captions, as much as it holds
-- names: xyz, abc, ...
can be placed in the first KB of SQL text- it may be part of the first query, but does not need to. It can also appear in the second or later queries.
-- name: xyz
has still priority, when also used for a single query
Here's an example, showing some special cases:
Please login to leave a reply, or register at first.