November 22nd, 2013, 12:45 AM
What makes query language tough?
I'm studying Intro to databases and I'm surprised how tough querying can be sometimes.
I wonder what makes it tough?
Is it the language constraints? Or is it because it is too strict and formal?
November 22nd, 2013, 01:05 AM
Well, I think I know about 50 languages and use about 10 of them regularly - and I could not agree SQL is tough.
On contrary many people with only basic knowledge of programming and web-design feel themselves comfortable enough with SQL.
So I fear the main reason is the lack of the relevant experience. However there are good news - as you practice, this problem will vanish.
It is not easy to become guru of databases and SQL because its depths are really unfathomable, however for novice it does not matter.
November 22nd, 2013, 01:13 AM
that's a pretty ... vague question. You might as well ask us why machines are sometimes so complex.
Are we talking about SQL here? Can you give an example of what you consider to be complex?
There are all kinds of reason for why people may say that a query is complex. Sometimes the task is complex. When you aggregate data from all kinds of sources or deal with complicated logic, it's only natural that the query will be complex as well. The language may also play a role. SQL is rather cumbersome, because every association has to be established with a join. This way you quickly end up with large queries for rather trivial data. And the perceived complexity depends on your experience. Since you're new to databases, it's not too surprising you find things hard to understand at first.
November 22nd, 2013, 01:35 AM
I'll try to be specific.
I'm talking about general query languages. Till now I've learnt three - relational algebra, relational calculus and MySQL.
Let me explain what I mean by tough - A query like find employees who work on all projects controlled by Department 5 (from my book) requires some thinking.
If we think informally, it seems so simple. Just check projects of all employees, if they match with that of department 5 then yes, else no.
When we actually write down query for this question, it seems a bit harder. You have to think a bit, right?
November 22nd, 2013, 02:34 AM
But you forget that the "everyday reasoning" was not the thing which you possess from birth. The same with, for example, English language. Some people learn it from childhood and did not think it is tough. Other people learn it in school or university - and they may say the language is far not easy.
So it is just the matter of practice - to get used to reasoning in the machine way.
The human brain works not the same way machines do, that is why we may misjudge the complexity or toughness of problems. For example for us looks not big deal to select the tallest man from group or to recognize people by face - while for computer the first task requires at least a loop through all the group and the second is so complex that it could be effectively programmed only by high-paid specialists (while the same task is easily solved even by the baby who hardly learned to speak).
November 22nd, 2013, 03:10 AM
MySQL is not a "query language".
Originally Posted by Avichal
It's a relational database management system which happens to use (a variation of) the query language "SQL".
Well that's true for any problem you have to solve: you need to think about it.
Whether that is a SQL query, a programming assignment, fixing the tires of your bicycle or baking a cake - you should always think before you do something.
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
Tips on how to ask better questions:
November 22nd, 2013, 03:33 AM
The problem is that you're obviously used to thinking procedurally: Do this, take that value, compare those values.
SQL and all other languages you've mentioned are declarative. This is a different way of thinking. It's not more complex, just different.
This is like learning a foreign language. If English is your native language, and you encounter French for the first time, you'll find it weird and difficult to understand. That doesn't mean French is actually more difficult than English. In fact, the French will probably claim the exact opposite.
Unfortunately, nowadays people are living in a bubble of procedural programming. At school or in university, you learn Java, C, Python or whatever. At home, you learn PHP or so. That's it. Of course SQL is a huge gap then. But if you're willing to learn something new and try out new languages, you'll realize that "the SQL way" isn't weird or complex at all.
Also note that MySQL isn't exactly a good representative of SQL the language. It lacks many fundamental features of SQL and requires a lot of workarounds. So just because something is complicated in MySQL doesn't mean that "SQL is bad".
Last edited by Jacques1; November 22nd, 2013 at 03:44 AM.