sql

sql statement to return all fields from all tables

select * from * yes this is what I want I want to return all fields from all table in my ACCESS database regardless the fields names or the tables names!!! for example if I have table1 and table2 as tables in my database access file what I want is to generate this statement select * from table1,table2 from sql query which run fin...

MySql Sql MAX and SUM error

select sum(value) as 'Value',max(value) from table_name where sum(value)=max(sum(value)) group by id_name; The error is: Invalid use of group function (ErrorNr. 1111) Any idea? Thanks. ...

crystal report (Having ) statement

I have an SQL query like SELECT GNTD_SCHEDULE_CODE SCHEDULE, GNTD_PARENT_ACCT PARENT_ACCOUNT, GNTD_ACCOUNT_CODE ACCOUNT, GNTD_COMP_CODE, SUM(CONVERT(FLOAT, ISNULL(GNTD_CUR_MNTH_ACT, 0))) CURR_MONTH_END, SUM(CONVERT(FLOAT, ISNULL(GNTD_PRV_PRD_ACT, 0))) PREV_MON...

duplicate value in a postgresql table

Hello i'm trying to modify a table inside my postgresql database, but it says there is duplicate! what is the best way to find a duplicate value inside a table? kinda a select query? ...

About PostgreSQL

Possible Duplicate: Good Postgres resources? Hi, I decided to get started on SQL and Databases management. After some research I decided to go for PostgreSQL. I'd like some advice about which book to buy on the subject. I'm looking for a book which teach you from scratch to an advanced level without taking you for a moron and...

MySql Group function error

select nume,model,sum(km_sosire-km_plecare) as 'km_parcursi' from masina m inner join (foaie_parcurs f inner join angajat a using(id_angajat)) using(id_masina) where sum(km_sosire-km_plecare)>100 group by a.nume,m.model order by sum(km_sosire-km_plecare); Error: Invalid use of group function Why? Thanks. ...

Using an Alias in SQL Calculations

Why won't this query work? SELECT 10 AS my_num, my_num*5 AS another_number FROM table In this example, I'm trying to use the my_num alias in other calculations. This results in unknown column "my_num" This is a simplified version of what I am trying to do, but basically I would like to use an alias to make other calculations. My ca...

Sql Server 2005 - Insert Update Trigger - Get updated, insert row

Hi all, I want to create a table trigger for insert and update. How can I get the values of the current record that is inserted/updated? ...

Paging in SQL with LIMIT/OFFSET sometimes results in duplicates on different pages

Hi community! I'm developing an online gallery with voting and have a separate table for pictures and votes (for every vote I'm storing the ID of the picture and the ID of the voter). The tables related like this: PICTURE <--(1:n, using VOTE.picture_id)-- VOTE. I would like to query the pictures table and sort the output by votes number...

sql query to return differences between two tables

I am trying to compare two tables, SQL Server, to verify some data. I want to return all the rows from both tables where data is either in one or the other. In essence, I want to show all the discrepancies. I need to check three pieces of data in doing so, FirstName, LastName and Product. I'm fairly new to SQL and it seems like a lot of...

Why can I not express this subquery? Is there an alternative?

I get an error: Subqueries are not allowed in this context. Only scalar expressions are allowed. Why are subqueries not allowed? I'm just trying to move some value over to another row in the same database. Is there another way of expression this quickly? (it's just a one-time operation...) INSERT INTO Html_Content (pageid, ht...

SQL - Call Stored Procedure for each record

Hi all, I am looking for a way to call a stored procedure for each record of a select statement. SELECT @SomeIds = ( SELECT spro.Id FROM SomeTable as spro INNER JOIN [Address] addr ON addr.Id = spro.Id INNER JOIN City cty ON cty.CityId = addr.CityId WHERE cty.CityId = @CityId ) WHILE @SomeIds IS NOT NULL BEGIN ...

Do we have transactions in MS-Access?

I am developing a small desktop application using C#.NET and MS-Access. I don't have any prior experience of MS-Access. I want to know if we can use transactions in Ms-Access or not. I have the below mentioned situation. Insert in Tbl1 Insert in Tbl2 I want to insert in tbl2 only when insertion in tbl1 is successful. And if there ...

Determine an value present in database sql php

I've created a dynamic table that will pull information from a database. However, there is 1 field that may have NOTHING in it, or it may have a bunch of information (from multiple check boxes) in it. I am trying to condense the initial table view (the details will show full db field information). What I have right now is this: if...

What's the best way to have a "repeating field" in SQL?

I'm trying to set up a table that links two records from a different table. These links themselves need to be correlated to another table. So at the moment, my table looks like this: link_id (primary key) item_id_1 (foreign key) item_id_2 (foreign key) link_type (metadata) However, the links between items are not directional (i...

Should I Quote Numbers in SQL?

I remember reading about quoting stuff when doing a sql query and that when you quote something, it becomes a string. I also read that numbers should not be quoted. Now, I cant find that quotation and I need to refresh my memory to see if I should quote numbers. ...

Running sql scripts against an attached database?

I've got an MDF attached to an instance of Sql Server 2008 Express, and I need to run some sql scripts against it to generate tables, indexes, etc. But I can't figure out how to get this to work. If I load the scripts in Visual Studio, it only allows me to connect to the server and run it against a database. I can't choose a different...

Need help with a SQL join in Rails

I have a table Blog belongs to User through user_id. I'm using thinking sphinx to index the blog, but I only want it to index blogs where the user is currently active (user.status = User::ACTIVE). I have the code below for creating the index, but I know the 'where' clause is wrong. What should it be? define_index do indexes title ...

SQL Query Question: Select all rows of n length, and then append a character

I have a ZIP code column where some of the zips came in without the leading zero. My goal is to: 1) select all rows in the zip column that are four characters in length (e.g. the zip code entries missing a zero) and then 2) append a '0' to these columns. I am able to select the rows: SELECT zip FROM contact WHERE zip LIKE "____...

Filtering access to admin

I have a side menu that I want to to have the Admin option ONLY display IF the username is an admin. Simply if they are an admin, it's there, if they are not it shows another link to their profile. Again, KISS (Keep It Super Simple)...please I am an noob. Thanks ...