how to show a specific word in a column? - mysql

I have a table which has various columns. One of them is called APP_DATA, and its fields are like this:
s:12:"project_code";s:4:"1025";s:18:"project_code_label";s:4:"1025"
I want to have a result that the output shows just project_code in the fields( not the other things)
I wrote a query like this:
SELECT A.APP_DATA AS app_data,ACV.APP_NUMBER AS app_number,
ACV.APP_STATUS AS app_status
FROM APP_CACHE_VIEW AS ACV
LEFT JOIN APPLICATION AS A ON
ACV.APP_NUMBER = A.APP_NUMBER
WHERE A.APP_DATA LIKE '%project_code%'
Unfortunately, the output of my query shows all of contents of APP_DATA. I like to have just a specific word!(just project_code)
How can I solve it?
Looking forward to your response

One easy way is to use SUBSTRING.
Example:
SELECT SUBSTRING(A.APP_DATA, 7, 12) AS app_data,ACV.APP_NUMBER AS app_number,
ACV.APP_STATUS AS app_status
FROM APP_CACHE_VIEW AS ACV
LEFT JOIN APPLICATION AS A ON
ACV.APP_NUMBER = A.APP_NUMBER
WHERE A.APP_DATA LIKE '%project_code%'
Example link
Careful, the index starts from 1.
For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.

Related

How can I use OR operator with 2 tables?

I'm trying to making a search option for my website project. I have to search 2 columns from 2 tables. After that, I'll write that query in my php code. Then it will list all the data about it. But it seems like I'm doing it wrong. What should I do?
select *
from mudurler,subeler,veriler
where mudurler.sube_id=subeler.sube_id
and veriler.sube_id=subeler.sube_id
and subeler.sube_ad like "%this%" or mudurler.adSoyad like "%that%"
When I go, if there is a valid value on sube_ad it works perfectly. But when i try to put valid value on adSoyad MySQL turns an empty result no matter what the value is.
You would have no problem if you used proper, explicit, standard JOIN syntax:
select *
from mudurler m join
subeler s
on m.sube_id = s.sube_id join
veriler v
on v.sube_id = s.sube_id
where s.sube_ad like '%this%' or
m.adSoyad like '%that%';
May be you should try:
and (subeler.sube_ad like "%this%" or mudurler.adSoyad like "%that%")

Setting boundary within MYSQ Query LIKE

I need to search products that are B196 not B196Y. Products are saved within Database in following format
B196 - Hair Band - Pink
SELECT * FROM
sn_unit
where
product LIKE 'B196%Hair Band%Pink';
You could just add space:
SELECT *
FROM sn_unit
where product LIKE 'B196 %Hair Band%Pink';
LIKE can be used to filter out results as well; something like this would be more precise.
SELECT *
FROM sn_unit
WHERE product LIKE 'B196%Hair Band%Pink'
AND product NOT LIKE 'B196Y%'
;
As you are looking your product store with string B196 so, you can search for that string LIKE %B196%. That will find out B196 and you are not looking for B196Y that need to exclude from your query. Thats why exlude it using NOT LIKE %B196y%. This query using AND operator that will return true when string contain only B196.
SELECT *
FROM sn_unit
WHERE product LIKE '%B196%'
AND product NOT LIKE '%B196Y%' ;

Inserting DATA in MS Access

I've this code:
SELECT VISA41717.Fraud_Post_Date, VISA41717.Merchant_Name_Raw, VISA41717.Merchant_City, VISA41717.Merchant_Country, VISA41717.Merchant_Category_Code, VISA41717.ARN, VISA41717.POS_Entry_Mode, VISA41717.Fraud_Type, VISA41717.Local_Amt, VISA41717.Fraud_Amt, VISA41717.Purch_Date, VISA41717.Currency_Code, VISA41717.Cashback_Indicator, VISA41717.Card_Account_Num
FROM VISA41717 LEFT JOIN MASTERCARD_VISA ON VISA41717.ARN=MASTERCARD_VISA.MICROFILM_NUMBER
WHERE VISA41717.ARN IS NULL OR MASTERCARD_VISA.MICROFILM_NUMBER IS NULL
ORDER BY VISA41717.ARN;
this is really works, But I need to match the first 6 digit of VISA41717.Card_Account_Num from BIN.INT to get the other data from BIN table and combined it all in one table only.
it should be this way:
Can you help me with this.
thanks!
What do you mean by 'all in one table'? Just build a query that joins tables.
Try:
SELECT ... FROM VISA41717 RIGHT JOIN BIN ON Left(VISA41717.Card_Account_Num, 6) = Bin.Int ...
Won't be able to build this join in Design View, use SQL View. Or build a query object that creates a field by extraction of the 6 characters and then build another query that includes that query and MASTERCARD_VISA and BIN tables.

MySQL WHERE clause not working after CSV import

I have a problem with a MySQL WHERE clause. I think I know what the problem is, just not how to fix it.
I have a database with student timetable information and I'm matching this against a table with student information. The student information has been imported into the database from a CSV (utf-8) file, the other information was just inserted into the database with "normal" INSERT queries.
The WHERE clause is simple and looks like this:
WHERE gpu_timetable.cls_name =
(SELECT cls_name FROM gpu_students WHERE std_number = 123441 LIMIT 1)
Its matching the cls_name (class name) from the timetable against the class name from the students table. Like I said the data is from different sources but looks to be the same. For example when I remove the SELECT query and use this string ('LV6A') the code works.
The collation on both of the fields is *utf8_general_ci*, I also tried TRIM() but no success, the same for replacing the operator = with LIKE.
Did I do something wrong when importing the student information or is there another function similar to TRIM() that can fix this weird problem?
Your simplified query must be:
SELECT * FROM gpu_timetable INNER JOIN gpu_students ON gpu_timetable.cls_name = gpu_students.cls_name WHERE gpu_students.std_number = 123441
Your should always have tablename.fieldname while using JOIN queries.

Returning Rank with Full Text Search Contains Query

I have implemented Full Text Search on one of Sql Server 2008 Table.
Query works fine when search some words using contains.
I want to filter out the result on the basis of Rank functionality of Full Text Search. I am writing the following query
SELECT rank, * FROM Mas_text
WHERE CONTAINS(text, 'Wanted and Engineers')
This query does not compile and give me error of "Invalid column name 'RANK'"
Please suggest.
The rank function doesn't work with the CONTAINS query. You'll have to use CONTAINSTABLE to get the rank. See here.
Should look something like this:
SELECT Mas_text.*, k.rank
FROM Mas_text
INNER JOIN CONTAINSTABLE(Mas_text, text, 'Wanted and Engineers') k
ON Mas_text.primarykey = k.[Key]