« first day (1672 days earlier)      last day (3196 days later) » 

7:34 AM
I have 2 tables Tasks and Maps. I need to update the Tasks.SESSIONID column via MAPS.subcategory and MAPS.category. However. there are mapping also for null values so my update doesn't work on the null values :
UPDATE t
SET    t.SESSTIONID = m.SESSTIONID
FROM   Tasks t
       JOIN maps m
            ON  t.Category__c = m.Category__c
            AND t.Sub_Category__c = m.Sub_Category__c
 
@RoyiNamir change the ON condition to how your mapping is
 
This is the maps table.
I need to tkae the sessionid via comparing category/subcategory in TASKS table
and to put it in TASKS.SESSIONID
 
ok
 
I could use isnull with special value....but it's ugly
 
How do the null map?
Are there nulls in Tasks columns as well?
 
7:37 AM
yes
 
in both columns?
 
In other words : look at TASKS , if the category is null and subcategory is null , then take the sessionid value from MAPS where maps.cat=null and maps.subcat = null
^
Yes
maps define all (!) mapping
 
and possibly one of the columns is not null and the other null ?
 
yes
take the combination from TASKS , and search that combination in MAPS and update the TASKS.sessionID
 
UPDATE t
SET    t.SESSTIONID = m.SESSTIONID
FROM   Tasks t
       JOIN maps m
            ON   (t.Category__c = m.Category__c OR t.Category__c IS NULL AND m.Category__c IS NULL)
            AND (t.Sub_Category__c = m.Sub_Category__c OR t.Sub_Category__c IS NULL AND  m.Sub_Category__c IS NULL)
and pray that you don't have 2 rows with all nulls
 
7:41 AM
in tasks ?
 
in maps
 
In tasks I do have :
 
@RoyiNamir You could probably use the technique described in this article by Paul White: sqlblog.com/blogs/paul_white/archive/2011/06/22/…
 
Ah yeah. The INTERSECT trick is awesome
It would fit your problem perfectly @RoyiNamir
 
7:45 AM
Thanks Andriy for the link , will read !
@ypercube I don't understand how it will impact if I have double in maps
 
if you have 2 rows with nulls, which of the two SessionID values will be used for the update you think?
 
Right ,so what will happen ?
(I can't test it. it's production env)
 
If yu have 2 rows, say with (null,null,1) and (null,null,2), both will match the condition and the related rows in tasks will be updated twice.
Whatever update is done last, is what you'll see.
 
oh :-)
will it actually update it twice ?
 
You can probably not have such issue, if there is unique constraint on maps (Category__c, SubCategory__c).
 
7:51 AM
I'm assuming @ypercube means if there are two such rows in MAPS. But if (MAPS.category, MAPS.subcategory) pairs are unique (and for the purpose of uniqueness test, NULLs are considered equal), then you shouldn't worry
 
Yes, what AndriyM said. Nulls and UNIQUE have special treatment in SQL-Server, which is good for your case.
 
Yes, the UNIQUE constraint on those two columns would be a good idea (at least if that matches the intent).
 
@AndriyM I think your answer wouldn't work as it is in MySQL: dba.stackexchange.com/questions/108811/…
Needs rewriting with JOIN. MySQL cannot handle the same table in WHERE and DELETE/UPDATE statements.
 
@ypercube I mixed that up then. Thought it was the other way round.
 
Thank you guys ( as always).
 
8:04 AM
@ypercube I remember there is this trick with nesting the table one level deeper. Do you know if it's reliable (as in "are there any gotchas about it")?
 
@AndriyM I never used it.
Joins are usually more "performant" ;)
 
Right :)
Except it should be a semi-join in this case, unless we can be certain that there can be no more than two rows of "almost duplicates" in this case.
 
Didnt work !
UPDATE t
SET    t.SESSTIONID = m.SESSTIONID
FROM   Tasks t
       JOIN maps m
            ON   (t.Category__c = m.Category__c OR t.Category__c IS NULL AND m.Category__c IS NULL)
            AND (t.Sub_Category__c = m.Sub_Category__c OR t.Sub_Category__c IS NULL AND  m.Sub_Category__c IS NULL)
 
What does this show? SELECT SessionID FROM Maps WHERE Category__c IS NULL AND Sub_Category__c IS NULL;
 
8:10 AM
no rows?
 
no rows.
but look :
 
Yes, your first image showed at least one row with null-null.
 
I can see a big difference between the two queries (other than the absence of WHERE)
 
Are you sure this is the same table?
 
The first one selected from Maps, the second one from RoyiTest.dbo.maps
 
8:13 AM
same
changed it to full :
UPDATE t
SET    t.SESSTIONID = m.SESSTIONID
FROM   [RoyiTest].[dbo].Tasks t
       JOIN [RoyiTest].[dbo].maps m
            ON   (t.Category__c = m.Category__c OR t.Category__c IS NULL AND m.Category__c IS NULL)
            AND (t.Sub_Category__c = m.Sub_Category__c OR t.Sub_Category__c IS NULL AND  m.Sub_Category__c IS NULL)
still , same result
 
Can you repeat @ypercube's query with a fully qualified the table name?
 
^ done it
 
Still [maps] is not the same as maps
 
I mean the SELECT one
 
SELECT SessionID FROM [RoyiTest].[dbo].[maps] WHERE Category__c IS NULL AND Sub_Category__c IS NULL;
 
8:15 AM
Is it the same server?
 
yes
server dstest / DB royitest.
there is no other !
 
You either runing in different dbs
or different schemas
or you have not nulls but the string 'NULL'
 
@ypercube Makes sense because in other screenshots the NULLs had a yellow background
and in the last one that showed data it was white
 
Yes, the Tasks has NULLs and the Maps has 'NULL's
 
@ypercube But it should work same as NULLs, right?
 
8:22 AM
@AndriyM No.
 
Sorry, meant that as a joke.
Anyway, well spotted.
 
oh boy, I thought you were trolling me. Need coffee.
 
Because we were close to finding another bug :)
 
@RoyiNamir The first image you posted (I guess from production) has NULLs in the Maps table. In your local test db, you have strings with 'NULL' instead.
 
8:27 AM
SELECT SessionID FROM [RoyiTest].[dbo].[maps] WHERE Category__c = 'NULL' AND Sub_Category__c = 'NULL';
 
UPDATE [RoyiTest].[dbo].[maps] SET Category__c = NULL WHERE Category__c = 'NULL';
UPDATE [RoyiTest].[dbo].[maps] SET Sub_Category__c = NULL WHERE Sub_Category__c = 'NULL';
 
what about the both cases where both are nulls ?
ps ( in 2 min i will delete the link)
 
morning
I think you are the only one who can answer your question. If you write a script for this (which is ready), you should know what you've implemented, right? — dezso 1 min ago
 
@RoyiNamir Those just update both columns separately, including the row where both are 'NULL'
 
8:31 AM
oh i see , you're fixing the mapping
 
yes
 
In a rather pervert way, we treat placing nulls as fixing today ;)
 
ALL good .
Thank you :-) and sorry
 
@ypercube somebodies just don't math
 
8:46 AM
@ypercube Thanks for your edit.
 
ps ( it was an exported Db from another company)
no way I would use null as strings
 
@AndriyM I didn't know if you wanted the first query removed or not.
 
9:02 AM
@ypercube Actually I wanted to stop pretending to be a MySQL expert :)
If I removed the first query, that would be essentially your answer posted under my name.
 
9:13 AM
Even if I could help you with a SQL query (of which I'm not sure), you would probably still need help integrating the query into your PHP script. However, it looks like you are using some framework which allows you to build database queries in a different way (I'm talking about this fragment: $attendance = DB::table('wys_teacherattendances') ->where('t_amonth', $amonth) ->where('t_ayear', $ayear) ->get(); – that's not SQL). I'm not familiar with that framework. Overall, it seems to me your question needs to be migrated to Stack Overflow. — Andriy M 11 secs ago
What are your thoughts?
 
 
3 hours later…
12:42 PM
@AndriyM You don't reply to them, sir ;)
thank you sir ..im also using this code($attendance = DB::table('wys_teacherattendances') ->where('t_amonth', $amonth) ->where('t_ayear', $ayear) ->get();) to my controller .php .but The output I get is incorrect format.. iam already post this question in stack overflow but no reply. i thought , problem in my sql query? — user71959 3 hours ago
 
1:04 PM
@ypercube and they are waiting for you :)
I've added composite indexes on both tables but seen no change in execution time or query plan. Could you elaborate on adding NOT EXISTS? — Tom 42 mins ago
 
1:53 PM
@Ypercube, @JackDouglas, @MarkStorey-Smith, @MarkSinkinson, @MartinSmith, @JamesLupolt - How does Friday 28 August sound for a drinkies?
2
 
Hm. not sure.
Friday 21 would be better for me
 
@MarkStorey-Smith - are you in town for Fri 28 Aug, or would some other date be better?
@ypercube - 21st works OK for me - let's see how it works for others.
 
@ConcernedOfTunbridgeWells Not that I complain but why the change from Thursdays to Fridays?
 
@ypercube Didn't we do Friday last time? I can't remember now.
 
oh yes, I think we did
 
2:09 PM
@TomV do you really think that joins without the JOIN syntax are more readable?
(BTW, congrats for making it into the BrentO newletter)
 
@ConcernedOfTunbridgeWells Any day before 21 would be ok, too. Family arrives at 22nd, so the first weeks - at least - I'll be busy ;)
 
@Vérace I am wondering if you missed postgres from the examples
22
A: Why should a key be made explicit?

VéraceYou are obviously suggesting that CONSTRAINTs in a database should be enforced by the application(s) that access that database? There are many reasons why this is a bad (bad, bad...) idea. 1) If you are building a "roll-your-own" constraint "engine" (i.e. within your application code), then you...

(BTW, congrats for making it into the BrentO newletter)
 
(BTW, congrats for making it into the BrentO newsletter)
 
2:27 PM
two parrots in the room!
 
2:54 PM
@dezso No - I didn't miss PostgreSQL - it's just that Oracle, MS SQL Server and MySQL are significantly more popular - though I have seen encouraging recent signs that PostgreSQL is finally making significant inroads in the MySQL juggernaut. Got a URL for the BrentO newsletter reference? I presume it's Brent Ozar?
 
@dezso You don't have the specific URL? That page has a number of links and no search facility.
 
Why Define Keys?

Why bother explicitly defining keys in your database?
 
@Vérace that's the newsletter
and @swasheck is right, as usual
8
Q: Why should a key be made explicit?

dsaxtonI am very new to the subject of databases so this may sound ignorant, but I am curious why a key should be made explicit within a table. Is this primarily to tell the user that the given column value is (hopefully) guaranteed to be unique within each row? The uniqueness should still be there ev...

 
@swasheck Thanks - I was searching for my name!
 
3:05 PM
@dezso you stand alone in that perception :)
 
@dezso I'm not getting the @swasheck reference. Is there something wrong with my answer in that thread?
 
i am le confused
 
@swasheck Moi aussi - confondu! (Me too, confused).
 
@Vérace nope. i was attempting to show you where the link to your answer appeared in the brent ozar newsletter
 
@Vérace I guess it would be listed if you joined that company
 
3:18 PM
@dezso Thanks for pointing it out - it's nice to have someone of his stature take note of my humble efforts :-). I took your remark about PostgreSQL to heart - edited post to include your favourite database and mine!
 
@dezso huh?
Re the join syntax (I don't seem to have a reply button on the mobile interface)
 
3:46 PM
18
A: Index performance on ON versus WHERE

Tom VThe performance will be the same. The optimizer will recognize this and create the same plan. On the other hand I wouldn't say they are equal. The first form is far more readable and generally expected. For an example using some tables I have at hand you can see the execution plan is exactly th...

 
"First form is far more readable" is referencing the first in Q not answer. Right?
 
@MikaelEriksson I'd think so.
 
@MikaelEriksson I'd hope so.
 
Yeah I meant in the op
 
@AaronBertrand will "make it so"
 
4:00 PM
Surely
 
don't call me shirley
 
4:42 PM
@AaronBertrand I agree with the edit😉
 
 
2 hours later…
6:16 PM
@MikaelEriksson I feel offended you think otherwise
btw @AaronBertrand, i'll be in utrecht next month
& you have a 1 hr train from antwerp to brussels airport
with a transfer unfortunately
 
when i say "full-thickness tear of the ACL and multiple sprains of the other collateral ligaments" you say ... ?
 
go see my dad?
(he's a kine)
 
6:31 PM
that's quite the trip from Denver :)
 
@swasheck Better you than me
 
@billinkc that's quite kind, coming from you
 
I am a font of kindness. Concern for humanity overfloweth
 
strange to get more rep while away than when posting
 
6:36 PM
 
didn't even think the post was that good when compared to some othrs
 
7:16 PM
nomination period began
Jul 27 at 20:00
election begins
in 44 minutes
 
campaigns were a bit weak though, especially on the bribery side of things
 
I predict the winner will be a member of The Heap.
5
 
@billinkc if you were billinUK you would even get that quoted
those bookies 'll bet you anything
 
It's my understanding the bookies in Las Vegas will do the same. People gamble on where the pitchers rosin bag falls
 
8:04 PM
Votes cast.
 
8:16 PM
1
Q: 2015 Moderator Election Q&A - Questionnaire

Grace NoteIn connection with the moderator elections, we are holding a Q&A thread for the candidates. Questions collected from an earlier thread have been compiled into this one, which shall now serve as the space for the candidates to provide their answers. Due to the lack of submission count, we have sel...

 
Four men enter, one man moderates
4
 
voted :)
 
8:45 PM
> MySQL is treated with mild contempt and NoSQL sometimes with open derision (though it is also widely recognised that both have their place). Is this a good thing? If not, how would you act as a moderator to encourage a different attitude in the community?
(though it is also widely recognised that both have their place) please cite your sources
 
Aug 30 '13 at 12:56, by Phil
True. NoSQL has existed from the start of CS. It had just never been named and productised before. Plenty of software used the concepts internally
:)
 
but i am talking about mysql
 
FaceBook?
I wouldn't like to try building FaceBook on postgres
 
@TomV I did not. But I thought @dezso did so I tried to help clear things a bit by pointing out that your answer could be interpreted to think you prefer join conditions in the where clause.
 
8:54 PM
I'm sure I remember some folk in here from time to time saying that MySQL is the best option in certain niches
the issue with MySQL and NoSQL is when it's used by default or because it's a fad, when another db would do better.
 
@JackDouglas totally agree. it just stinks that so many decision-makers buy into the fad
 
too true
 
@swasheck is this acquired by you?
 
@dezso yep.
 
@swasheck geez sorry
 
9:06 PM
kine1 (archaic) plural of cow
kine2 kinescope
@swasheck ugh
 
@bluefeet it's my fault.
but thanks
 
did you do something to get it?
 
@swasheck your fault?
 
@dezso @bluefeet playing in a competitive softball league i slid into home and my cleat caught on the edge of home plate. leg and knee stopped. body didnt.
 
ugh that sounds painful
 
9:09 PM
actually wasnt as bad as it sounds ... it's just stiff and annoying. probably going to require surgery ... and skiing is in jeopardy. was going to do warrior dash in a few weeks
... that seems off the table now
 
@JackDouglas do you think you had to change more than they had with MySQL?
 
@JackDouglas @JackDouglas yeah ... why's that?
 
heh, Rolando is having some fun
2
A: Inserting emoji - smartphones in MySQL database with PHP?

RolandoMySQLDBAI have this sinking feeling inside that you have a character set problem if you are using InnoDB. When you connect to MySQL, run this query select A.variable_name, A.variable_value global_value, B.variable_value session_value from ( select * from information_schema.global_variab...

 
@swasheck if you don't want to leave your lower leg somewhere in the mud...
 
@dezso i've got another
 
9:13 PM
always good to have spare parts around
 
@swasheck multi-master replication is more of a thing with MySQL
 
now I've checked the top reps here - last time I really noticed it was over 30k
now these two with 84k are monsters
 
@dezso not sure what you mean?
 
@JackDouglas did FB use a vanilla MySQL?
 
I guess they started with that, not sure tbh
 
9:16 PM
but they ended up somewhere else :)
 
pretty sure they googled the heck out of mysql.
 
@swasheck Lunch tomorrow?
 
@MikeFal working on it right now
 
@dezso I believe this is the branch of MySQL that FB and others ended up with: webscalesql.org
This blog, which you've probably seen, has a lot of interesting info about MySQL at FB: dom.as
It seems like they are focusing a lot on Mongo now, somewhat to my surprise
 
9:42 PM
@JamesLupolt which, AFAIK, they don't recommend for the use of anybody else, because it's so heavily modified
 
9:52 PM
@swasheck gute Besserung
and a good night to all
 
10:10 PM
@JackDouglas Actually, it's been named for decades: ISAM.
 

« first day (1672 days earlier)      last day (3196 days later) »