i have a database that already has a users table
COLUMNS:
userID - int
loginName - string
First - string
Last - string
i just installed the asp.net membership table. Right now all of my tables are joined into my users table foreign keyed into the "userId" field
How do i integrate asp.net_users table into my schema? here are the ideas i thought of:
Add a membership_id field to my users table and on new inserts, include that new field in my users table. This seems like the cleanest way as i dont need to break any existing relationships.
break all existing relationship and move all of the fields in my user table into the asp.net_users table. This seems like a pain but ultimately will lead to the most simple, normalized solution
any thoughts?
for a current webapp i need a "outlook-like" calendar... Here are some requirements for the calendar:
week-view for the appointments
different appointment types
direct display of the length and time of the date (like in googleCalendar)
multiple appointments for the same time
only using javascript, php and any DB
We need the calendar for the Zend Framework, so if the Calendar doesn't already support the ZF, the source needs to be editable!
do you know any calendar which fits my needs? or do you have any tipps for developing one by myself?
So I'm trying to take a search string (could be any number of words) and turn each value into a list to use in the following IN statement) in addition, I need a count of all these values to use with my having count filter
$search_array = explode(" ",$this->search_string);
$tag_count = count($search_array);
$db = Connect::connect();
$query = "select p.id
from photographs p
left join photograph_tags c
on p.id = c.photograph_id
and c.value IN ($search_array)
group by p.id
having count(c.value) >= $tag_count";
This currently returns no results, any ideas?
I have 2 tables:
Dictionary - Contains roughly 36,000 words
CREATE TABLE IF NOT EXISTS `dictionary` (
`word` varchar(255) NOT NULL,
PRIMARY KEY (`word`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Datas - Contains roughly 100,000 rows
CREATE TABLE IF NOT EXISTS `datas` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`hash` varchar(32) NOT NULL,
`data` varchar(255) NOT NULL,
`length` int(11) NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `hash` (`hash`),
KEY `data` (`data`),
KEY `length` (`length`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=105316 ;
I would like to somehow select all the rows from datas where the column data contains 1 or more words.
I understand this is a big ask, it would need to match all of these rows together in every combination possible, so it needs the best optimization.
I have tried the below query, but it just hangs for ages:
SELECT `datas`.*, `dictionary`.`word`
FROM `datas`, `dictionary`
WHERE `datas`.`data` LIKE CONCAT('%', `dictionary`.`word`, '%')
AND LENGTH(`dictionary`.`word`) > 3
ORDER BY `length` ASC
LIMIT 15
I have also tried something similar to the above with a left join, and on clause that specified the like statement.
hi!
the query is:
select employee_id, last_name, salary, round((salary+(salary*0.15)), 0) as
NewSalary, (round((salary+(salary*0.15)), 0) - salary) as “IncreaseAmount”
from employees;
can i optimize this round((salary+(salary*0.15)), 0) part in anyway, so that it doesn't appear twice..i tried giving it an alias but didn't work :(
I have a table where a record looks like this
varchar(255) Name
varchar(255) Text
varchar(255) Value
Name is the DDL name, Text is what is displayed, and Value is returned upon selection. There are between one and twenty options for each Name. Without iterating though each option like a cursor, is there any way to pull out a list of objects, one for each unique DDL Name, using Linq and C#?
A sample of the data:
Beds '4 (10)' 4
Beds '5 (1)' 5
Beds '7 (1)' 7
Baths 'NA (13)' NULL
Baths '0 (1)' 0
Baths '1 (13)' 1
I was thinking about doing an outer select to get the unique Names, then an inner select to get the list of options for it, then return the set as a List of a set of Lists.
I have a form with many fields...
The action is set to a php page which queries mysql...
Should I sanitize with mysql_real_escape_string every single variable?
Or can I ignore sanitizing drop-lists and radios for instance?
Also, besides mysql_real_escape_string, what else should I do to prevent attacks?
Thanks
I was trying to run the following query
UPDATE blog_post SET `thumbnail_present`=0, `thumbnail_size`=0, `thumbnail_data`=''
WHERE `blog_post` NOT IN (
SELECT `blog_post`
FROM blog_post
ORDER BY `blog_post` DESC
LIMIT 10)
But Mysql doesn't allow 'LIMIT' in an 'IN' subquery.
I think I can make a select to count the table rows and then make an ordered update limited by 'COUNT - 10', but I was wondering if there is a better way.
Thanks in advance.
what is the proper way of doing the following:
getting DATE as user input
running a query
generating a report that uses the query
this is the solution i was thinking:
have a form that takes user input
run the query
open the report
what is the correct way of doing this?
result=sqlstring.executeQuery("select distinct table_name,owner from all_tables ")
rs.append(str(i)+' , '+result.getString("table_name")+' , '+result.getString("owner"))
If i want to display the query select * from all_tables or ' select count(*) from all_tables'
how can i get the output to display . Please suggest thanks
I need to get the most recent record for each device from an upgrade request log table. A device is unique based on a combination of its hardware ID and its MAC address. I have been attempting to do this with GROUP BY but I am not convinced this is safe since it looks like it may be simply returning the "top record" (whatever SQLite or MySQL thinks that is).
I had hoped that this "top record" could be hinted at by way of ORDER BY but that does not seem to be having any impact as both of the following queries returns the same records for each device, just in opposite order:
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created DESC
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created ASC
Is there another way to accomplish this? I've seen several somewhat related posts that have all involved sub selects. If possible, I would like to do this without subselects as I would like to learn how to do this without that.
If you have a table with a clustered index on the Primary Key (int), is it redundant and bad to have one (ore more) non-clustered indexes that include that primary key column as one of the columns in the non-clustered index?
I'm using SMS 2008 & I'm looking for where the registered servers are stores on my local machine. I have searched the registry with no luck.
AHIA,
Larry...
I have a column whose value is a json array. For example:
[{"att1": "1", "att2": "2"}, {"att1": "3", "att2": "4"}, {"att1": "5", "att2": "6"}]
What i would like is to provide a view where each element of the json array is transformed into a row and the attributes of each json object into columns. Keep in mind that the json array doesn't have a fixed size.
Any ideas on how i can achieve this ?
Hello,
Specifications: MySQL 4.1+
I've certain situation that requires certain result set from MySQL query, let's see the current query first & then ask my question:
SELECT thread.dateline AS tdateline, post.dateline AS pdateline, MIN(post.dateline)
FROM thread AS thread
LEFT JOIN post AS post ON(thread.threadid = post.threadid)
LEFT JOIN forum AS forum ON(thread.forumid = forum.forumid)
WHERE post.postid != thread.firstpostid
AND thread.open = 1
AND thread.visible = 1
AND thread.replycount >= 1
AND post.visible = 1
AND (forum.options & 1)
AND (forum.options & 2)
AND (forum.options & 4)
AND forum.forumid IN(1,2,3)
GROUP BY post.threadid
ORDER BY tdateline DESC, pdateline ASC
As you can see, mainly I need to select dateline of threads from 'thread' table, in addition to dateline of the second post of each thread, that's all under the conditions you see in the WHERE CLAUSE. Since each thread has many posts, and I need only one result per thread, I've used GROUP BY CLAUSE for that purpose.
This query will return only one post's dateline with it's related unique thread.
My questions are:
How to limit returned threads per
each forum!? Suppose I need only 5
threads -as a maximum- to be
returned for each forum declared in
the WHERE CLAUSE 'forum.forumid
IN(1,2,3)', how can this be
achieved.
Is there any recommendations for
optimizing this query (of course
after solving the first point)?
Notes:
I prefer not to use sub-queries, but if it's the only solution available I'll accept it. Double queries not recommended. I'm sure there's a smart solution for this situation.
Appreciated advice in advance :)
My table looks like this with duplicates in col1
col1, col2, col3, col4
1, 1, 0, a
1, 2, 1, a
1, 3, 1, a
2, 4, 1, b
3, 5, 0, c
I want to select distinct col1 with max (col3) and min(col2);
so result set will be:
col1, col2, col3, col4
1, 2, 1, a
2, 4, 1, b
3, 5, 0, c
I have a solution but looking for best ideas?
i am trying to write a statment for counting the employees attendance and execute thier id , name and the days that he has working on the last 3 months by counting the duplicate id on NewTimeAttendance for month 1 , 2 and 3 ..
i tried to count :
Select COUNT(employeeid) from NewTimeAttendance where employeeid=1 and (month=1 or month =2 or month = 3)
This is absolutely working ,but just for one employee...
the secound try:
SELECT COUNT(NewEmployee.EmployeeID)
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
This is working , but it counts all employees .. and i want it to execute each EmployeeId, EmployeeName and number of days as new record
last try: (before you see the code ... it is wrong ..but i am trying)
for i in 0..27 loop
SELECT COUNT(NewEmployee.EmployeeID),NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID(i) = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
end loop
i realy need help...thanks in advance
I need a way to store an int for N columns. Basically what I have is this:
Armies:
ArmyID - UINT
UnitCount1 - UINT
UnitCount2 - UINT
UnitCount3 - UINT
UnitCount4 - UINT
...
I can't possible add a column for each and every unit, so I need a fast way to store the number of each units in an army (you might have guesses it's for a game by now). Using XML is not an option as it will be dead slow.
Here are my tables
respondents:
field sample value
respondentid : 1
age : 2
gender : male
survey_questions:
id : 1
question : Q1
answer : sample answer
answers:
respondentid : 1
question : Q1
answer : 1 --id of survey question
I want to display all respondents who answered the certain survey, display all answers and total all the answer and group them according to the age bracket.
I tried using this query:
SELECT
res.Age,
res.Gender,
answer.id,
answer.respondentid,
SUM(CASE WHEN res.Gender='Male' THEN 1 else 0 END) AS males,
SUM(CASE WHEN res.Gender='Female' THEN 1 else 0 END) AS females,
CASE
WHEN res.Age < 1 THEN 'age1'
WHEN res.Age BETWEEN 1 AND 4 THEN 'age2'
WHEN res.Age BETWEEN 4 AND 9 THEN 'age3'
WHEN res.Age BETWEEN 10 AND 14 THEN 'age4'
WHEN res.Age BETWEEN 15 AND 19 THEN 'age5'
WHEN res.Age BETWEEN 20 AND 29 THEN 'age6'
WHEN res.Age BETWEEN 30 AND 39 THEN 'age7'
WHEN res.Age BETWEEN 40 AND 49 THEN 'age8'
ELSE 'age9'
END AS ageband
FROM Respondents AS res
INNER JOIN Answers as answer ON answer.respondentid=res.respondentid
INNER JOIN Questions as question ON answer.Answer=question.id
WHERE answer.Question='Q1' GROUP BY ageband ORDER BY res.Age ASC
I was able to get the data but the listing of all answers are not present. Do I have to subquery SELECT into my current SELECT statement to show the answers?
I want to produce something like this:
ex: # of Respondents is 3 ages: 2,3 and 6
Question: what are your favorite subjects?
Ages 1-4:
subject 1: 1
subject 2: 2
subject 3: 2
total respondents for ages 1-4 : 2
Ages 5-10:
subject 1: 1
subject 2: 1
subject 3: 0
total respondents for ages 5-10 : 1
today my problem is this i have 2 column and i wish check if the sum of that columns isn't Higher then a value(485 for example) and if is do a query...i though to do
SELECT * FROM table WHERE ColumnA+ColumnB<485
But isn't working... i've already tried with
SELECT Sum(ColumnA)+Sum(ColumnB) AS Total FROM table
but it gives me 1 column with the sum of all rows, i instead want a row for every sum. so how can i do..? xD i hope you understood if not just ask that i try to explain it better! and thanks in advice for who want to help me!
EDIT: I Found out XD the problem was that the columns was Smallint and the result of 1 or more rows was more than 32k so it wasn't working! Thanks At all!!
I am trying to do something like this but am having trouble putting it into oracle coding.
BEGIN
IF ((SELECT complete_date FROM task_table WHERE task_id = 1) IS NULL)
THEN
UPDATE task_table SET complete_date = //somedate WHERE task_id = 1;
ELSE
UPDATE task_table SET complete_date = NULL;
END IF;
END;
But this does not work i also tried
IF EXISTS(SELECT complete_date FROM task_table WHERE task_id = 1)
with no luck
Hey all
i have 3 tables each as follow
cash_credit
Bank_Name-------in_date-------Com_Id---Amount
America Bank 15/05/2010 1 200
HSBC 17/05/2010 3 500
Cheque_credit
Bank_Name-----Cheque_Number-----in_date-------Com_Id---Amount
America Bank 74835435-5435 15/05/2010 2 600
HSBC 41415454-2851 17/05/2010 5 100
Companies
com_id----Com_Name
1 Ebay
2 Google
3 Facebook
4 Amazon
Companies table is a linked table when i tried to create an query as follow
SELECT cash_credit.Amount, Companies.Com_Name, cheque_credit.Amount
FROM cheque_credit INNER JOIN (cash_credit INNER JOIN Companies ON cash_credit.com_id = Companies.com_id) ON cheque_credit.com_id = Companies.com_id;
I get an error saying that my inner Join is incorrectly, this query was created using Access 2007 query design
the error is
Type mismatch in expression
then i thought it might be the inner join so i tried Left Join and i get an error that this method is not used
JOIN expression is not supported
I am confused on where is the problem that is causing all this
Hi all,
I'm a lone developer for a telecoms company, and am after some database design advice from anyone with a bit of time to answer.
I am inserting into one table ~2 million rows each day, these tables then get archived and compressed on a monthly basis. Each monthly table contains ~15,000,000 rows. Although this is increasing month on month.
For every insert I do above I am combining the data from rows which belong together and creating another "correlated" table. This table is currently not being archived, as I need to make sure I never miss an update to the correlated table. (Hope that makes sense) Although in general this information should remain fairly static after a couple of days of processing.
All of the above is working perfectly. However my company now wishes to perform some stats against this data, and these tables are getting too large to provide the results in what would be deemed a reasonable time. Even with the appropriate indexes set.
So I guess after all the above my question is quite simple. Should I write a script which groups the data from my correlated table into smaller tables. Or should I store the queries result sets in something like memcache? I'm already using mysqls cache, but due to having limited control over how long the data is stored for, it's not working ideally.
The main advantages I can see of using something like memcache:
No blocking on my correlated table after the query has been cashed.
Greater flexibility of sharing the collected data between the backend collector
and front end processor. (i.e custom reports could be written in the
backend and the results of these stored in the cache under a key which
then gets shared with anyone who would want to see the data of this report)
Redundancy and scalability if we start sharing this data with a large amount of customers.
The main disadvantages I can see of using something like memcache:
Data is not persistent if machine is rebooted / cache is flushed.
The main advantages of using MySql
Persistent data.
Less code changes (although adding
something like memcache is trivial
anyway)
The main disadvantages of using MySql
Have to define table templates every time I want to store provide a new set of grouped data.
Have to write a program which loops through the correlated data and fills these new tables.
Potentially will still grow slower as the data continues to be filled.
Apologies for quite a long question. It's helped me to write down these thoughts here anyway, and any advice/help/experience with dealing with this sort of problem would be greatly appreciated.
Many thanks.
Alan