If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Interview Questions by Van Tay Media on Unsplash
MySQL interview देना है? तो सिर्फ basic questions से आगे बढ़ना जरूरी है! आज के competitive job market में, tricky और advanced MySQL questions आपके interview को next level पर ले जा सकते हैं।
इस blog में हम discuss करेंगे कुछ ऐसे MySQL के tricky interview questions जो अक्सर interviewers पूछते हैं, ताकि आप confidently अपने next interview में perform कर सकें।
●●●
Question : अगर table में दो या ज़्यादा rows बिल्कुल identical/same हैं, तो आप सिर्फ एक row कैसे delete करेंगे?
Answer : इस situation में simple `WHERE` clause काम नहीं करेगा क्योंकि सारी rows identical हैं। आपको `ROWID` या `LIMIT` का use करना पड़ेगा। MySQL में आप `DELETE` के साथ `LIMIT` use कर सकते हैं।
Identify duplicate rows
SELECT column1, column2, COUNT(*)
FROM your_table
GROUP BY column1, column2
HAVING COUNT(*) > 1;
Delete duplicate rows
WITH cte AS (
SELECT id, column1, column2,
ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY id) AS row_num
FROM your_table
)
DELETE FROM your_table
WHERE id IN (SELECT id FROM cte WHERE row_num > 1);Question : NULL values के साथ comparison कैसे करते हैं? = operator काम करेगा?
Answer : NULL को compare करने के लिए इस NULL या इस NOT NULL use करना चाहिए। = operator NULL के लिए काम नहीं करता क्योंकि NULL का मतलब unknown होता है।
SELECT * FROM employees WHERE manager_id IS NULL;
or
SELECT * FROM employees WHERE manager_id IS NOT NULL;
Answer : Aggregate functions जैसे SUM(), COUNT(), AVG() NULL values को ignore करते हैं। लेकिन COUNT(*) सब rows count करता है, चाहे NULL हो या न हो।
इसलिए हमेशा एक particular column को count करें जैसे primary id.
Answer : Indexes data को fast access करने के लिए use होते हैं। Composite index multiple columns पर बनाया जाता है जो queries को optimize करता है जब multiple columns filter या join में use हो रहे हो।
Answer : Transaction isolation levels define करते हैं कि एक transaction दुसरे transaction के changes को कब तक देख सकता है।
Common levels हैं -
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ (MySQL का default)
SERIALIZABLE
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);●●●
MySQL में Charset, Encoding, और Collation 3 important concepts हैं जो text data को store करने और retrieve करने के लिए use किये जाते हैं।
Character Set (Charset) एक collection होता है characters का, जिसमे हर character का एक unique numeric value (code point) होता है। मतलब, एक charset एक collection of characters को define करता है, जो आप अपने database में store कर सकते हो।
Example : utf8, latin1, utf8mb4
UTF-8 एक popular character set है, जिसमे दुनिया के सारे languages के characters का representation हो सकता हैं जैसे English, Hindi, Arabic, Chinese, etc.।
Encoding का मतलब है एक specific character को binary data (bytes) में convert करना, ताकि उससे store किया जा सके। हर charset का अपना encoding method होता है, जिसमे character को bytes के form में convert किया जाता है।
UTF-8 encoding हर character को 1 से 4 bytes तक में encode करता है।
Charset character set को represent करता है।
Encoding एक particular character set के characters को bytes में convert करने का process है।
Example :
अगर आप UTF-8 charset use कर रहे हो, तो UTF-8 encoding use करके characters को 1 से 4 bytes तक encode किया जायगा।
latin1 charset के case में, हर character 1 byte में encode होता है।
Collation एक set of rules होता है जो determine करता है कि characters को compare और sort कैसे किया जायगा। Collation का use query results को order करते वक्त होता है और text comparison में भी होता है।
Collation case sensitivity और accent sensitivity को define करता है। For example, क्या 'a' और 'A' को same treat किया जायेगा या अलग?
Collation में sorting rules भी होते हैं, जैसे किसी specific language के characters को किस order में arrange करना है।
Types of Collation:
Case Sensitive : utf8_bin — 'a' और 'A' को अलग characters treat किया जाता है।
Case Insensitive : utf8_general_ci — 'a' और 'A' को same characters treat किया जाता है।
CI का मतलब है Case Insensitive
BIN का मतलब है Binary, मतलब case-sensitive और exact match.
Example :
utf8_general_ci : ये collation general case-insensitive comparison allow करता है. तो 'a' और 'A' को same consider किया जायेगा।
utf8_unicode_ci : ये collation Unicode characters को compare करता है, जो ज़्यादा accurate और language-specific sorting provide करता है।
●●●
Loading ...