sql

Help writing a mysql query - this mustve been done 1000 times before but I am struggling..please help?

Update: I am editing my question in the hope of getting a better answer. I see this is not so simple but I cant believe there is not a simpler solution than what has been mentioned so far. I am now looking to see if there is some kind of php, mysql solution to deal with this in the most efficent way. I have modified my question below to ...

SQL Conditional Select Statement

Hello all, How would I go about doing the following? Given the tables, Recipe, RecipeItem, RecipeInstruction. How do I perform a SELECT only if the SELECT statement of Recipe returned results. If Recipe exists, return RecipeItems and return RecipeInstructions. ...

Printing Results in a Simple Table

I have a MySQL table with a structure similar to this: id1 id2 title url date I would like to print out a simple table in PHP that with the following structure sorted in reverse chronological order for the most recent 10 entries (date above = date submitted) from the MySQL table: title id2 How could I do this? ...

SQL database Structure

I've got a list of synonyms and need to create a database in SQL for it. I was thinking about using a Relational Database Design, but don't know if it would be the best. There will be a decent amount of traffic using this database. I was thinking about Table1 would be like Id Table2 Id InterlinkID (Table1 Id) Word Would this be th...

Revoking permission in oracle

In Oracle, if the current user tries to revoke all his permissions, what'll happen? For example, if I'm a user(John) created with WITH GRANT OPTION - can I revoke my permissions? ...

display records randomly one after another

hi I want to display 5 records from a database with in a td one after another (about 60sec). How will i do this, with out the need of page refreshing? I don't know any idea about ajax ...

Problem with UTL_FILE.FCOPY in a trigger

I am new to triggers. I created a trigger below: CREATE OR REPLACE TRIGGER ac01_control_trigg AFTER INSERT ON AC01_CONTROL_TEST FOR EACH ROW DECLARE BEGIN IF :NEW.cur_pgm_name = 'LSN' AND :NEW.nxt_pgm_name ='MD' AND :NEW.file_status='RD' THEN UTL_FILE.Fcopy (:NEW.FILE_PATH,:NEW.FILE_NAME,:NEW.FILE_PATH,'CP.txt'); INSERT ...

Stored procedure in SQL Server (distinct)?

I write a stored procedure in SQL Server like this select distinct top 5 videos.videoid,videos.videotitle,videos.videoname, convert(varchar,videos.posteddate,106) as posteddate,videos.approvedstatus, videos.videoimage,(ISNULL(videos.views,0.0)) as [views],videos.privacy, (isnull(videos.rating,0.0)) as rating,videos.userid, u...

how to stop using a database index for a particular query?

Is there way to do it? I am currently facing problem as one index is being used unnecessarily in my query (as displayed in the execution plan of the query in sql server 2008) and it is degrading the query performance. This index can not be dropped as it is useful for some other query. ...

Retrieving users for specific SQL Server databases

Hi there: I have a few SQL Server databases (all in one server), containing their own set of users. Now I'm trying to design a small application that would query those users and then display them in a report (TBD). I've looked over online how to do this, however I didn't find any. Is it possible in SQL Server to retrieve all the users ...

Doing a data compare with T-SQL in a query in SQL Server 2005

Hi! Wondering if anyone knows an easy way to do this. I have a couple of tables with data, this data is "static" in that way that users don't change it, it's only me that gets to insert/update rows. And I wonder if there's an easy way to insert rows that don't exists and update rows that are different. The way that I figured would work ...

"correct" way to select next sequence value in HSQLDB 2.0.0-rc8

suppose i have a sequence, called TEST_SEQ what would be the correct way of selecting its next value ? this does not work: select next value for TEST_SEQ probably because it expects a "FROM" clause. looking at HSQLDialect.getSequenceNextValString() in hibernate i see this: "select next value for " + sequenceName + " from dual_" + sequ...

Mark a record as 'in use' to support multithreading

My (simplified) table consist of an Id int identity(1,1), File varchar(20), FileProcessed bit The logic is this: my application takes first (the order isn't important) record, which has FileProcessed bit set to false. Then it processes the file and sets the FileProcessed bit to true. Now, it can happen, that the first thread takes a ...

Transforming nvarchar day duration setting into datetime

I have a SQL Server function which converts a nvarchar day duration setting into a datetime value. The day duration format is >days<.>hours<:>minutes<, for instance 1.2:00 for one day and two hours. The format of the day duration setting can not be changed, and we can be sure that all data is correctly formatted and present. Giving th...

How can I order by Greek Letters and Normal Letters in SQL Server?

I have a mix of greek and normal words and now the order of these is that the normal words comes first and then all the greek words. I want them to get mixed in the order so beta in greek is the same as B. How can I make this ORDER BY in SQL Server? ...

Why historically do people use 255 not 256 for database field magnitudes?

You often see database fields set to have a magnitude of 255 characters, what is the traditional / historic reason why? I assume it's something to do with paging / memory limits, and performance but the distinction between 255 and 256 has always confused me. varchar(255) Considering this is a capacity or magnitude, not an indexer, why...

Problem with ROWNUM

I have a view. one of the view's column contains NVL function (like nvl(col1,col2) colA). and if i made query on this i will display some records Ex: select calA from view1; and if i use the same query as inline view and i use rownum in where clause it displays nothing Ex: Select * from (select calA from view1) where rownum <10; I a...

Counting number of children in hierarchical SQL data

Hello, for a simple data structure such as so: ID parentID Text Price 1 Root 2 1 Flowers 3 1 Electro 4 2 Rose 10 5 2 Violet 5 6 4 Red Rose 12 7 3 Television 100 8 3 Radio 70 9 8 ...

MySQL queries and text search

I have this query: select name, body from news where body like %MyWord%; I use MySQL database engine. this query will return name, body when found MyWord in body text. My problem here is that, when I search about two word in body text, like MyWord1 , MyWord2. or more !!! How I can do that if you know that this query is calling by...

One mysql table with many fields or many (hundreds of) tables with fewer fields?

Hello, I am designing a system for a client, where he is able to create data forms for various products he sales him self. The number of fields he will be using will not be more than 600-700 (worst case scenario). As it looks like he will probably be in the range of 400 - 500 (max). I had 2 methods in mind for creating the database ...