w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Find Matches in MYSQL by uknown common Words
I'd start off by asking someone with Domain Knowledge for their absolute top 2 or 3 recurring problems. They should be able to just reel these off. Ask them to supply you with the terms and synonyms used in those 2 or 3 main problems, else you will have to do this yourself. Clone the table and put a FULLTEXT index on it and see how effective fulltext search is in identifying matching issues. I would be surprised if this does not yield pretty good results from the corpus, but if they are not good enough then you might want to wander into the field of NLP (Natural Language Processing) - a more natural fit for that would be the toolset that you can use with Python though. Another alternative is to build in some kind of tagging system, but the best ones rely on human intervention and thei

Categories : PHP

Do SELECT on the last INSERT in MySQL or INSERT data into 2 tables which have a common column that is auto generated by MySQL
Just use LAST_INSERT_ID(), it contains the last auto generated key in the session (ie from your previous insert) INSERT INTO invisible SET username='$username', password='$password'; INSERT INTO user_info SET user_id=LAST_INSERT_ID(); A simple SQLfiddle.

Categories : Mysql

Return multiple mySQL rows that have one common column value, place into separate arrays...?
If you are using PHP, you might want something like: $dbh = Database::connect(); $query = "SELECT * FROM CraftShows WHERE Date = ?"; $sth = $dbh->prepare($query); $sth->execute(array($date)); for($i=0 ; $i<$sth->rowCount() ; $i++){ $show[$i] = $sth->fetch(); } return $show; OBS: if your table CraftShows has, for instance, the columns a, b and c, then each element of $show will be an array with 3 elements (a, b and c). For exeple, $show[2]["b"] will contain the field b for the third row fetched in the query. OBS2: Database is supposed to be the PHP class that connects with your database. Something like: class Database { public static function connect() { $dsn = 'mysql:dbname=name_here;host=host_here'; $user = 'username_here'; $passwor

Categories : PHP

How to find that a value in column has related value in another row in mysql
First, Bluefeet is right. You should store your data in a normalized format. That is, you should have a table called something like MenuConflicts, with one column for Menu_Name and another for one Conflict. That said, you can do what you want with an arcane join using find_in_set(): select * from t t1 join t t2 on find_in_set(t2.menu_name, t1.conflicts) > 0 where find_in_set(t1.menu_name, t2.conflicts) = 0; The join matches any row where the second menu name is in the first conflict list. The where clause then checks the additional reciprocal condition.

Categories : Mysql

MySQL - Find pairs in either column
For Simpson, you want to include rows where either name is "Simpson", but the name you want to select (and count for) is the "non-Simpson" name. You can do it like this: SELECT CASE WHEN Name1 <> 'Simpson' THEN Name1 ELSE Name2 END AS ClickName, SUM(count) AS ClickCount FROM fullNames WHERE 'Simpson' IN (Name1, Name2) GROUP BY CASE WHEN Name1 <> 'Simpson' THEN Name1 ELSE Name2 END ORDER BY ClickCount DESC

Categories : PHP

MySQL Find First Colum's String, Echo Second Column's
Okay, see below for a basic implementation example: $host = "localhost"; $user = "user"; $password = "pass"; $database = "db"; $con=mysqli_connect($host,$user,$password,$database); if(mysqli_connect_errno()!=0)//mysqli_connect_errno() returns 0 when there are no errors { echo "ERROR"; } $sifre_test = mysqli_real_escape_string($con,$_POST['pass']); $result = mysqli_query($con,"SELECT '1' FROM `keyler` WHERE `sifre`='".$sifre_test."'"); if($result!==false) { //If $result !== false, the query was successful, so we'll try to grab a row $row = mysqli_fetch_assoc($result); //$row will be null if there wasn't a row found where `sifre`=$sifre_test if(!is_null($row)) { $result = mysqli_query($con,"SELECT `bizimkey` FROM `keyler` WHERE `sifre`='".$sifre_test."'");

Categories : PHP

Cannot find the column after committed update (JDBC, MySQL)
You've computers_id in //SELECT block and ID in //UPDATE. Try this in //UPDATE block String queryUpdate="UPDATE computers SET name=?, serial=?, inv_number=?, comments=?, rack_unit=?, box_unit=?, ram=? WHERE computers_id=" +currentComp.getComputers_id();

Categories : Java

how can i find all column with full text index in mysql 4.1.22
As documented under SHOW INDEX Syntax: SHOW INDEX returns the following fields: [ deletia ] Index_type The index method used (BTREE, FULLTEXT, HASH, RTREE). Comment Various remarks. Before MySQL 4.0.2 when the Index_type column was added, Comment indicates whether an index is FULLTEXT. You can then parse the results to determine over which columns FULLTEXT indexes have been defined.

Categories : Mysql

mysql - find most popular two column value combination and sort by popularity
Here is SQLFiddle SELECT COUNT(*) AS `Rows`, FOOD, BRAND FROM `foods` GROUP BY FOOD, BRAND ORDER BY `Rows` DESC

Categories : PHP

MySQL Find first and last rows of rows with matching values in the same column
Because the sequencing of hte ID and date columns match, you can use the following. SELECT id ,date ,unique_id FROM ( SELECT min(id) as id ,min(date) as date ,unique_id ,count(id) as rec_count from table group by unique_id union SELECT max(id) as id ,max(date) as date ,unique_id ,count(id) as rec_count from table group by unique_id ) SQ WHERE SQ.rec_count > 1

Categories : Mysql

find least common multiple of numbers 1-20
why can't you simply find gcd by euclid's algorithm and the multiply the numbers and divide by gcd to find LCM? def decorator(d): """This is a decorator that will decorate all decorators. This will add update_wrapper to all decorators. (fun) -> fun """ def _d(f): return update_wrapper(d(f), f) return update_wrapper(_d, d) @decorator def nary(f): """This is docp implementation of n_ary function above. (function) -> function Tue-23-April-2013 """ def n_ary(x, *args): if len(args) == 0: return x return f(x, n_ary(*args)) return n_ary @nary def gcd(a, b): """Calculate the Greatest Common Divisor of a and b. Unless b==0, the result will have the same sign as b (so that when b is divided by

Categories : Python

Find most common value from hashmap of set in java?
note: not sure if this is the fastest, but this is one way to do this. First, write a simple method to extract the frequencies for the Strings occurring across all value sets in the map. Here is a simple implementation: Map<String, Integer> getFrequencies(Map<String, Set<String>> map) { Map<String, Integer> frequencies = new HashMap<String, Integer>(); for(String key : map.keySet()) { for(String element : map.get(key)) { int count; if(frequencies.containsKey(element)) { count = frequencies.get(element); } else { count = 1; } frequencies.put(element, count + 1); } } return new frequencies; } You can simply call this method like this: M

Categories : Java

Find common substring between two strings
def common_start(sa, sb): """ returns the longest common substring from the beginning of sa and sb """ def _iter(): for a, b in zip(sa, sb): if a == b: yield a else: return return ''.join(_iter()) >>> common_start("apple pie available", "apple pies") 'apple pie' Or a slightly stranger way: def stop_iter(): """An easy way to break out of a generator""" raise StopIteration def common_start(sa, sb): ''.join(a if a == b else stop_iter() for a, b in zip(sa, sb)) Which might be more readable as def terminating(cond): """An easy way to break out of a generator""" if cond: return True raise StopIteration def common_start(sa, sb): ''.join(a for a, b in zip(sa, sb)

Categories : Python

Find the most common words in a website
Assuming you really want to find only words contained in paragraphs, and are happy with your regexp, this is the minimal change to get the total word count of the retrieved document: soup = BeautifulSoup(ourUrl) dem = soup.findAll('p') #find paragraphs word_counts = Counter() for i in dem: # loop for each para words = re.findall(r'w+', i.text) cap_words = [word.upper() for word in words] word_counts.update(cap_words) print word_counts To ignore common words, one method would be to define a frozenset of ignorable words: word_counts = Counter() stopwords = frozenset(('A', 'AN', 'THE')) for i in dem: # loop for each para words = re.findall(r'w+', i.text) cap_words = [word.upper() for word in words if not word.upper() in stopwords] word_counts.update(cap_word

Categories : Python

php to display table; column one with mysql column comments and column two transposed row results
I'd recommend you use the mysqli fetch_fields() function on the result set, to get information about the columns contained in the resultset, rather than querying views in INFORMATION_SCHEMA. The fetch_fields() will work for queries that reference only a subset of columns in a table, or queries that return expressions, or return columns from more than one table. http://php.net/manual/en/mysqli.quickstart.metadata.php

Categories : PHP

SQL: how to select common lines of one table on several column
Fot the first part of the question, try this query: SELECT DISTINCT t1.page FROM a t1 WHERE (SELECT COUNT(DISTINCT t2.pro) FROM a t2 WHERE t2.page = t1.page) = (SELECT COUNT(DISTINCT t3.pro) FROM a t3) And the second query is the simple substraction from all page values: SELECT DISTINCT t4.page FROM a t4 EXCEPT SELECT DISTINCT t1.page FROM a t1 WHERE (SELECT COUNT(DISTINCT t2.pro) FROM a t2 WHERE t2.page = t1.page) = (SELECT COUNT(DISTINCT t3.pro) FROM a t3)

Categories : SQL

How to get a list of tables which contains a common column value in SQL Server
try select table_name from information_schema.columns where column_name='Asset_ID' If you want to get the table names depending on the value of data in the column you cannot get it by simple query try the following declare @val_to_search varchar(50), @column_name varchar(50) Select @val_to_search = 'ddh224', @column_name='Asset_ID' declare tbl cursor for select table_name from information_schema.columns where column_name=@column_name declare @tablename varchar(200),@qstr varchar(max) declare @datapen table(table_name varchar(200)) open tbl fetch tbl into @tablename while @@fetch_status=0 begin select @qstr='select top 1 '''+@tablename+''' from '+@tablename+' where '+ @column_name + ' =''' + @val_to_search + '''' insert into @datapen exec(@qstr) fetch tbl into @tablename end close tbl

Categories : SQL

How to find equal elements with common parent in XML?
I would first turn each element into canonical form by sorting the children into order; this is easily done with XSLT. The result should be such that two elements are equal according to your rules if and only if their canonical forms are deep-equal() according to XPath 2.0. I would then write a function that computes some kind of hashcode for each element (so that "equal" elements have equal hashcodes) and perform grouping on this hashcode. Again this is easily done with XSLT 2.0: the only difficult bit is designing the hash function. I suspect your example doesn't show the real data, and I would want to see the real data before suggesting a hash function. Then within each hashcode group you can use XSLT 2.0's deep-equal() function to compare every member of the group against every other

Categories : C#

How to find common parts in a paths with perl?
You probably need to do it "step-by-step", in the 1st step you should organize the same md5 files. One idea: take the Graph::Easy for each file what has same md5 convert the path to Graph and each time you find already existing edge (path) increment the edge atribute - counter. when added all paths, you can traverse the graph to find edges what has the counter > 1, so more files has the same path part. unfortunately don't know how exactly to do this - but maybe you can get some idea or someone other will refine the solution.

Categories : Perl

intersect and any or contains and any. Which is more efficient to find at least one common element?
See Matthew's answer for a complete and accurate breakdown. Relatively easy to mock up and try yourself: bool found; double intersect = 0; double any = 0; for (int i = 0; i < 100; i++) { List<string> L1 = GenerateNumberStrings(200000); List<string> L2 = GenerateNumberStrings(60000); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); found = Intersect(L1, L2); stopWatch.Stop(); intersect += stopWatch.ElapsedMilliseconds; stopWatch.Reset(); stopWatch.Start(); found = Any(L1, L2); stopWatch.Stop(); any += stopWatch.ElapsedMilliseconds; } Console.WriteLine("Intersect:

Categories : C#

Find common elements in two unsorted array
Although this would be a cheat, since it uses HashSets, it is pretty nice for a Java implementation of this algorithm. If you need the pseudocode for the algorithm, don't read any further. Source and author in the JavaDoc. Cheers. /** * @author Crunchify.com */ public class CrunchifyIntersection { public static void main(String[] args) { Integer[ ] arrayOne = { 1, 4, 5, 2, 7, 3, 9 }; Integer[ ] arrayTwo = { 5, 2, 4, 9, 5 }; Integer[ ] common = iCrunchIntersection.findCommon( arrayOne, arrayTwo ); System.out.print( "Common Elements Between Two Arrays: " ); for( Integer entry : common ) { System.out.print( entry + " " ); } } public static Integer[ ] findCommon( Integer[ ] arrayOne, Integer[ ] arrayT

Categories : Java

Algorithm to find common ancestor of two nodes given
You can follow this approach While traversing Binary Search Tree from top to bottom, the first node n we encounter with value between n1 and n2, i.e., n1 < n < n2 is the Lowest or Least Common Ancestor(LCA) of n1 and n2 (where n1 < n2). So just traverse the BST in pre-order, if you find a node with value in between n1 and n2 then n is the LCA, if it's value is greater than both n1 and n2 then our LCA lies on left side of the node, if it's value is smaller than both n1 and n2 then LCA lies on right side. Its a commonly asked programming question in interview you could have easily found its solution on interview sites

Categories : Database

Find most common element Linked List
One way to do it will be to use a key transformation or hash function. Use a hash on the name and if the hashed value matches, increment the count for that name by one. Return the one with the highest count.

Categories : C

How to best use SQL to find common IDs that match multiple WHERE clauses
How about self join? SELECT T1.ID FROM PropertyTable T1 JOIN PropertyTable T2 ON T1.ID = T2.ID WHERE T1.PropertyName = 'Color' AND T1.PropertyValue = 'Blue' AND T2.PropertyName = 'Size' AND T2.PropertyValue = 'Large' Here is an SQLFiddle

Categories : SQL

Combining two files in linux (or R) with duplicated with one common column
This should dot it: merge(dat,dat1,by.x='tag',by.y='tag') tag stat stat.1 P.value V2 V3 1 L2_None_chr1_-_109092036 0.3049 7.464 1.875e-11 chr1 109092034 2 L2_None_chr1_-_109092036 0.2961 7.448 2.105e-11 chr1 109092034 3 L2_None_chr1_-_109092036 0.2934 7.347 3.389e-11 chr1 109092034 4 L2_None_chr1_-_109092036 0.2961 7.245 5.668e-11 chr1 109092034 5 L2_None_chr1_-_109957962 0.6682 7.284 4.664e-11 chr1 109957879 6 L2_None_chr1_-_109957962 0.6682 7.284 4.664e-11 chr1 109957879 7 L2_None_chr1_-_159842839 0.3933 7.363 3.127e-11 chr1 159842779 8 L2_None_chr1_-_159842839 0.3808 7.284 4.672e-11 chr1 159842779 9 L2_None_chr1_-_169972458 0.2993 7.170 8.278e-11 chr1 169972444 10 L2_None_chr1_-_203626998 0.3312 7.817 3.075e-12 chr1 203626983 11 L2

Categories : Linux

How to find common part among all items in the string list?
Here is an algorithm: Take the first string as root. For each item in the list If root is longer than item root.truncate(item.length()); For each index i in root If root [ i ] does not match item [ i ] root.truncate( i ); Edit: some code that I haven't tested but "should" work. c++03 code: QString find_root(const QStringList& list) { QString root = list.front(); for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) { if (root.length() > it->length()) { root.truncate(it->length()); } for(int i = 0; i < root.length(); ++i) { if (root.at(i) != it->at(i)) { root.truncate(i); break; } } } retur

Categories : C++

Rails has_and_belongs_to_many find unique objects in common
I think you were almost there. Just exclude conversations with outsiders with an additional NOT EXISTS anti-semi-join: SELECT c.* FROM conversations c JOIN conversations_phones AS cp1 ON cp1.conversation_id = c.id AND cp1.phone_id = ? JOIN conversations_phones AS cp2 ON cp2.conversation_id = c.id AND cp2.phone_id = ? ... WHERE NOT EXISTS ( SELECT 1 FROM conversations_phones cp WHERE cp.conversation_id = c.id AND cp.phone_id NOT IN (cp1.phone_id, cp2.phone_id, ...) -- or repeat param ) , @phone1.id, @phone2.id, ... I pulled conditions into the JOIN clause for simplicity, doesn't change the query plan. Goes without saying that you need indices on conversations(id) and conversations_phones(conver

Categories : SQL

function to find common rows between more than two data frames in R
Rewritten: common <- function(a, b, c, d) { Name <- a$Name inB <- Name %in% b$Name inC <- Name %in% c$Name inD <- Name %in% d$Name which(!(inB | inC | inD)) }

Categories : R

How to extract the common words before particular symbol and find particular word
You can use split to get the common part: s = "g18_84pp_2A_MVP1_GoodiesT0-HKJ-DFG_MIX-CMVP1_Y1000-MIX.txt" n = s.split('-')[0] In fact, split will give you a list of each token delimited by '-', so s.split('-') yields: ['g18_84pp_2A_MVP1_GoodiesT0', 'HKJ', 'DFG_MIX', 'CMVP1_Y1000', 'MIX.txt'] To see if MIX or FIX is in a string, you can use in: if 'MIX' in s: print "then MIX is in the string s" If you want to get rid if the numbers after 'MVP', you can use re module: import re s = 'g18_84pp_2A_MVP1_GoodiesT0' s = re.sub('MVP[0-9]*','MVP',s) Here is a sample function to get a list of the common parts: def foo(mydict): return [re.sub('MVP[0-9]*', 'MVP', k.split('-')[0]) for k in mydict]

Categories : Python

How to find common rows in two sets of query results?
You have two queries: SELECT * FROM hmdb WHERE shamsidate MATCH '1376/05/24 1385/11/12' SELECT * FROM hmdb WHERE hmdb MATCH 'content:red OR keyword:red v_other:true' Just combine the where conditions and use one query instead using an AND clause (and parentheses to keep the logic consistent): SELECT * FROM hmdb WHERE shamsidate MATCH '1376/05/24 1385/11/12' AND (hmdb MATCH 'content:red OR keyword:red v_other:true')

Categories : C#

How to find elements that are common to all lists in a nested list?
You can use reduce and set.intersection: >>> reduce(set.intersection, map(set, nested_list)) set([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]) Use itertools.imap for memory efficient solution. Timing Comparisons: >>> lis = [[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0]] >>> %timeit set.intersection(*map(set, lis)) 100000 loops, best of 3: 12.5 us per loop >>> %timeit set.intersection(*(set(e) for e in lis)) 10000 loops, best of 3: 14.4 us per loop >>> %timeit reduce(

Categories : Python

Find greatest common subtype of two Scala types
Sounds like you want a Least Upper Bound (LUB) of the scala types? I would look to Miles' Shapeless library for inspiration where they actually have a LUBConstraint. Or if you want the Greater Lower Bound (GLB) I'm afraid I'd have to refer you to using a macro definition wherein you can get either the LUB or the GLB, see Types.

Categories : Scala

MySQL - Selecting common value
SELECT id FROM chat AS c INNER JOIN chat_user AS cu1 ON c.id = cu1.chat_id INNER JOIN chat_user AS cu2 ON c.id = cu2.chat_id AND cu1.id < cu2.id INNER JOIN user AS u1 ON u1.id = cu1.user_id INNER JOIN user AS u2 ON u2.id = cu2.user_id WHERE u1.external_id = 111 AND u2.external_id = 222 The AND cu1.id < cu2.id part forces the chat_user with id 1 to be joined es cu1 and the chat_user with id 2 to be joined as cu2. This eliminates the record where the chat_user with id 2 is joined as cu1 and the chat_user with id 1 is joined as cu2. My guess is that you omitted this clause in your attempts and this resulted in duplicates.

Categories : Mysql

Selecting rows that share a common value in one column, but were selected by other values
Get all rows that match the inputs using WHERE, then GROUP BY the car_id HAVING at least one row for each of the input. You can use the query below to do that. SELECT car_id FROM CarOptions WHERE (description = "tinted windows" OR description = "power windows") GROUP BY car_id HAVING SUM(description = "tinted windows") > 0 AND SUM(description = "power windows") > 0 See demo To get entire row you can do, SELECT * FROM CarOptions WHERE car_id IN ( SELECT car_id FROM CarOptions WHERE (description = "tinted windows" OR description = "power windows") GROUP BY car_id HAVING SUM(description = "tinted windows") > 0 AND SUM(description = "power windows") > 0)

Categories : Mysql

Pandas Combining 2 Data Frames (join on a common column)
Joining fails if the DataFrames have some column names in common. The simplest way around it is to include an lsuffix or rsuffix keyword like so: restaurant_review_frame.join(restaurant_ids_dataframe, on='business_id', how='left', lsuffix="_review") This way, the columns have distinct names. The documentation addresses this very problem. Or, you could get around this by simply deleting the offending columns before you join. If, for example, the stars in restaurant_ids_dataframe are redundant to the stars in restaurant_review_frame, you could del restaurant_ids_dataframe['stars'].

Categories : Python

Add auto-incrementing column in temporary Common Table Expression
You just need an analytic query, for instance row_number(), which returns the sequence of a row, within a partition (not required), and in the order specified. select col, row_number() over ( order by col ) as id from temp

Categories : SQL

How can I merge two csv files by a common column, in the case of unequal rows?
Read data from the shorter file into memory, into a dictionary keyed on the LOGRECNO row: import csv with open('sample_state_census.csv', 'rb') as census_file: reader = csv.reader(census_file, delimiter=' ') census_header = next(reader, None) # store header census = {row[9]: row for row in reader} then use this dictionary to match against the geo data, write out matches: with open('sample_state_geo.csv', 'rb') as geo_file: with open('outputfile.csv', 'wd') as outfile: reader = csv.reader(geo_file, delimiter=' ') geo_header = next(reader, None) # grab header geo_header.pop(6) # no need to list LOGRECNO header twice writer = csv.writer(outfile, delimiter=' ') writer.writerow(census_header + geo_header) for row in reader

Categories : Python

Where do I find release notes/changelog for common Node.js modules
A lot of module authors don't include any changelog or history unfortunately. Fortunately for you though, some of the most popular ones do. Uncoincidentally, all of the ones that you posted are by TJ Holowaychuk who does a good job of updating a Changelog in a file he names History.md. Express: https://github.com/visionmedia/express/blob/master/History.md Connect: https://github.com/senchalabs/connect/blob/master/History.md Stylus: https://github.com/LearnBoost/stylus/blob/master/History.md Look for a file named something like history.md or changelog.md otherwise you're stuck with commit logs. I hope this helps some.

Categories : Node Js

Objective-C algorithm to find largest common subsets of arrays?
You are looking for an algorithm to find the cardinality of a set intersection. Depending on your set representation, you could choose different ways of doing it. The most performant representation for this would be using bits in an integer, but if the number of possible interests exceeds 64 this may not be easy to implement. A straightforward way of implementing it would be with NSMutableSet, like this: // Prepare the individual lists NSArray *chris = @[@"bowling", @"gaming", @"skating", @"running"]; NSArray *brad = @[@"bowling", @"jumping", @"walking", @"sitting"]; // Obtain the intersection NSMutableSet *common = [NSMutableSet setWitArray:chris]; [common intersectSet:[NSSet setWithArray:brad]]; NSLog(@"Common interest count: %i", common.count);

Categories : Objective C

Perl read a file and an array and find common words
There are several problems: You do not chomp $c. The filename contains a newline at the end. You use the 2-argument form of open, but do not test the second argument. This is a security problem: do you know what happens if the user input contains > or |? You use == to compare strings. String equality is tested with eq, though, == tests numbers. Moreover, you do not want to know whether "Sam" equals to "John is the uncle of Sam". You want to know whether it is a part of it. You might need to use index or regular expressions to find out. Do not use $a as the name of a variable, it is special (see perlvar).

Categories : Arrays



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.